1 solutions

  • 0
    @ 2022-10-24 22:28:35
    #include<bits/stdc++.h>
    using namespace std;
    #define ioio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    #define endl "\n"
    #define debug(x) cout<<#x<<":"<<x<<endl;
    #define P pair
    #define P1 first
    #define P2 second
    #define u_map unordered_map
    #define p_queue priority_queue
    typedef long long ll;
    const double eps = 1e-6;
    const int mod = 1e9 + 7;
    const int INF = 0x3f3f3f3f;
    const int N = 1e5+ 7;
    int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
    /*-------------------------------------------------*/
    
    int n,m;
    int fa[N];
    int cnt[N];
    
    int fin(int x){
    	if(x!=fa[x])
    		fa[x]=fin(fa[x]);
    	return fa[x];
    }
    void mer(int x,int y){
    	x=fin(x),y=fin(y);
    	if(x==y)return ;
    	fa[x]=y;
    	cnt[y]+=cnt[x];
    }
    void slove(){
    	cin>>n>>m;
    	for(int i=1;i<=n;i++){
    		fa[i]=i;
    		cnt[i]=1;
    	}
    	int x,y;
    	for(int i=1;i<=m;i++){
    		cin>>x>>y;
    		mer(x,y);
    	}
    	cin>>x;
    	cout<<cnt[fin(x)]<<endl;
    }
    int main(){
    	ioio
    	int t=1;
    	//cin>>t;
    	while(t--)
    		slove();
    	return 0;
    }
    

    Information

    ID
    6640
    Time
    1000ms
    Memory
    256MiB
    Difficulty
    6
    Tags
    # Submissions
    36
    Accepted
    12
    Uploaded By