Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- ll max_ll(ll x, ll y){
- return ((x>y)?(x):(y));
- }
- int main()
- {
- ll n,m;
- cin>>n>>m;
- vector<ll> adj[n+1];
- map <pair<ll,ll>,ll> mp;
- for (ll i=1; i<=m; i++){
- ll x,y;
- cin>>x>>y;
- if ((x>=y && mp[make_pair(x,y)]<1) || (x<y && mp[make_pair(y,x)]<1)){
- adj[x].push_back(y);
- adj[y].push_back(x);
- if (x>=y) mp[make_pair(x,y)]++;
- else mp[make_pair(y,x)]++;
- }
- }
- ll groups=0, ans=0;
- vector <bool> visited(n+1,false);
- for (ll i=1; i<=n; i++){
- if(!visited[i]){
- visited[i]=true;
- groups++;
- queue <ll> q;
- q.push(i);
- while(!q.empty()){
- ll v=q.front();
- q.pop();
- for (auto u:adj[v]){
- if (!visited[u]){
- visited[u]=true;
- groups++;
- q.push(u);
- }
- }
- }
- }
- ans=max_ll(ans,groups);
- groups=0;
- }
- cout<<ans<<"\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement