/***
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
vector<int> G[30005] ;
int visited[30005] ;
queue<int> q ;
void reset(int n)
{
int i ;
for(i=1; i<=n ; i++)
{
G[i].clear() ;
visited[i] =0 ;
}
}
int BFS(int src)
{
int cnt=0,i,v,u;
cnt++ ;
q.push(src) ;
visited[src] =1 ;
//pf("%d\n",cnt) ;
while(!q.empty())
{
u = q.front() ;
q.pop() ;
for(i=0 ; i<G[u].size() ; i++)
{
v = G[u][i] ;
if(!visited[v])
{
cnt++ ;
visited[v] =1 ;
q.push(v) ;
}
}
}
//pf("%d\n",cnt) ;
return cnt ;
}
int main()
{
int test ,n, i,m,u,v ;
sc("%d",&test) ;
while(test--)
{
sc("%d %d",&n,&m) ;
reset(n) ;
for(i=1 ; i<=m ; i++)
{
sc("%d %d",&u,&v) ;
G[u].pb(v) ;
G[v].pb(u) ;
}
//pf("Hello\n") ;
int mx =0 ;
for(i=1 ; i<=n ; i++)
{
if(!visited[i])
{
//pf("Hello\n") ;
int k = BFS(i) ;
if(k>mx)
mx =k ;
}
}
pf("%d\n",mx) ;
}
return 0;
}
Md. Namzul Hasan
Shahjalal University of Science & Technology,Sylhet.
hasan08sust@gmail.com
***/
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll ;
typedef int in ;
typedef unsigned long long ull ;
const double pi = 2*acos(0) ;
#define maxi 40000
#define pf printf
#define sc scanf
#define pb push_back
#define MEM(x,y) (memset((x),(y),sizeof(x)))
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))
#define load(array,size) for(int i=0 ; i<size ; i++) cin>>array[i] ;
#define new_line pf("\n")
#define clear_data(array) memset(array,0,sizeof(array))
#define highest_int 2147483647
vector<int> G[30005] ;
int visited[30005] ;
queue<int> q ;
void reset(int n)
{
int i ;
for(i=1; i<=n ; i++)
{
G[i].clear() ;
visited[i] =0 ;
}
}
int BFS(int src)
{
int cnt=0,i,v,u;
cnt++ ;
q.push(src) ;
visited[src] =1 ;
//pf("%d\n",cnt) ;
while(!q.empty())
{
u = q.front() ;
q.pop() ;
for(i=0 ; i<G[u].size() ; i++)
{
v = G[u][i] ;
if(!visited[v])
{
cnt++ ;
visited[v] =1 ;
q.push(v) ;
}
}
}
//pf("%d\n",cnt) ;
return cnt ;
}
int main()
{
int test ,n, i,m,u,v ;
sc("%d",&test) ;
while(test--)
{
sc("%d %d",&n,&m) ;
reset(n) ;
for(i=1 ; i<=m ; i++)
{
sc("%d %d",&u,&v) ;
G[u].pb(v) ;
G[v].pb(u) ;
}
//pf("Hello\n") ;
int mx =0 ;
for(i=1 ; i<=n ; i++)
{
if(!visited[i])
{
//pf("Hello\n") ;
int k = BFS(i) ;
if(k>mx)
mx =k ;
}
}
pf("%d\n",mx) ;
}
return 0;
}
No comments:
Post a Comment