//\\__ hr1212 __//\\
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,parent[MAX],sz[MAX],ht[MAX];
map<string,int> mm;
int findp(int x){
return (parent[x]==x)?x:findp(parent[x]);
}
void unionset(int p,int q){
if(findp(p)!=findp(q)){
int x,y;
x=findp(p);y=findp(q);
if(ht[x]>ht[y]){
parent[y]=x;
sz[x]+=sz[y];
}
else{
parent[x]=y;
sz[y]+=sz[x];
if(ht[x]==ht[y])
ht[y]++;
}
}
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p,q;
while(1){
sii(n,m);
if(n==0 && m==0)
break;
mm.clear();
k=0;
clr(ht,0);
f(i,0,n){
cin>>p;
mm[p]=k;
parent[k]=k;
sz[k++]=1;
}
f(i,0,m){
cin>>p>>q;
unionset(mm[p],mm[q]);
}
z=-1;
f(i,0,k){
z=max(z,sz[i]);
}
pi(z);
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef map<int,int> mi;
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define nl printf("\n");
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define f(i,a,b) for(i=a;i<b;i++)
#define rf(i,a,b) for(i=a;i>=b;i--)
#define clr(x,a) memset(x,a,sizeof(x))
#define MAX 1000100
#define MOD 1000000007
int n,m,parent[MAX],sz[MAX],ht[MAX];
map<string,int> mm;
int findp(int x){
return (parent[x]==x)?x:findp(parent[x]);
}
void unionset(int p,int q){
if(findp(p)!=findp(q)){
int x,y;
x=findp(p);y=findp(q);
if(ht[x]>ht[y]){
parent[y]=x;
sz[x]+=sz[y];
}
else{
parent[x]=y;
sz[y]+=sz[x];
if(ht[x]==ht[y])
ht[y]++;
}
}
}
int main(){
int r,k,i,c=0,x=0,y=0,j,t,l,z,x1=0,y1=0;
ll ans=0;string p,q;
while(1){
sii(n,m);
if(n==0 && m==0)
break;
mm.clear();
k=0;
clr(ht,0);
f(i,0,n){
cin>>p;
mm[p]=k;
parent[k]=k;
sz[k++]=1;
}
f(i,0,m){
cin>>p>>q;
unionset(mm[p],mm[q]);
}
z=-1;
f(i,0,k){
z=max(z,sz[i]);
}
pi(z);
}
return 0;
}
No comments:
Post a Comment