/*
o我知道了,这里并不需要动态查询祖宗,所以直接不用压缩
就用fa表示父亲即可
我今天一定要切掉三值逻辑
并查集与程序判断不同,代表的是数值关系
*/
#include<bits/stdc++.h>
using namespace std;
const int N = 100015, TRU = 200001, FAL = 200002, UN = 200003;
int fa[N * 2];
int c, T;
int n, m;
void init()
{
for(int i = 1; i < N * 2; i ++)fa[i] = i;
}
int get(int x)
{
if(fa[x] == x)return x;
return fa[x] = get(fa[x]);
}
int main()
{
// freopen("tribool4.in", "r", stdin);
// freopen("1.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> c >> T;
while(T --)
{
init();
cin >> n >> m;
for(int i = 1; i <= m; i ++)
{
char op;
cin >> op;
if(op == '+')
{
int x, y;
cin >> x >> y;
fa[x] = get(y);
fa[x + n] = get(y + n);//总是要这样的
}
else if(op == '-')
{
int x, y;
cin >> x >> y;
fa[x] = get(y + n);
fa[x + n] = get(y);
}
else
{
int x;cin >> x;
if(op == 'T')
{
fa[x] = get(TRU);
// fa[x + n] = get(FAL);
}
else if(op == 'F')
{
fa[x] = get(FAL);
// fa[x + n] = get(TRU);
}
else
{
fa[x] = get(UN);
// fa[x + n] = get(UN);
// fa[x + n] = get(UN);
}
}
}
int cnt = 0;
for(int i = 1; i <= n; i ++)
{
if(get(i) == get(i + n) || get(i) == UN)
{
cnt ++;
}
}
cout << cnt << endl;
}
return 0;
}
这样为啥不对啊