2 条题解

  • -3
    @ 2023-7-16 14:47:12
    #include <bits/stdc++.h>
    #define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    #define re register
    using namespace std;
    typedef long long ll;
    int fth[20010], n, m, x, y, tx, ty, ans;
    vector<int> enmy[20010];
    char opt;
    int fnd(int t)
    {
    	return (fth[t]==t?t:fth[t]=fnd(fth[t]));
    }
    int main()
    {
    	IOS;
    	cin>>n>>m;
    	for(int i=0; i<=2*n; i++) fth[i]=i;
    	for(int i=0; i<m; i++)
    	{
    		cin>>opt>>x>>y;
    		if(opt=='F') fth[fnd(x)]=fnd(y);
    		else
    		{
    			fth[fnd(x+n)]=fnd(y);
    			fth[fnd(y+n)]=fnd(x);
    		}
    	}
    	for(int i=1; i<=n; i++) if(fth[i]==i) ans++;
    	cout<<ans;
    	return 0;
    } 
    

    信息

    ID
    457
    时间
    1000ms
    内存
    128MiB
    难度
    4
    标签
    递交数
    42
    已通过
    23
    上传者