跑下大样例试试?
by CaiZi @ 2023-11-30 21:23:11
@[CaiZi](/user/728853) 大样例格式有问题,跑不了
by Liyuqiao11 @ 2023-11-30 21:39:28
用洛谷题目下面的试试
by CaiZi @ 2023-11-30 22:06:19
我又重新改了一版,还是40分但是是从第三个点到第六个点AC了
by Liyuqiao11 @ 2023-12-03 12:10:14
```c
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+10;
#define int long long
vector<pair<int,int> > G[N];
bool flag;
int c,t,n,m,last[N],bz[N],col[N],siz[N],tot;
void dfs(int x){
siz[tot]++;
for(int i=0;i<G[x].size();i++){
int v=G[x][i].first,w=G[x][i].second;
if(col[v]!=0){
if(w==0){
if(col[v]!=col[x]){
flag=false;
}
}
if(w==1){
if(col[v]==col[x]){
flag=false;
}
}
}
else{
if(w==0) col[v]=col[x];
if(w==1){
if(col[x]==1){
col[v]=1;
}
if(col[x]==2){
col[v]=3;
}
if(col[x]==3){
col[v]=2;
}
}
dfs(v);
}
}
}
signed main(){
cin>>c>>t;
while(t--){
int ans=0;
tot=0;
cin>>n>>m;
for(int i=1;i<=n+2;i++){
siz[i]=0;
col[i]=0;
last[i]=i;
bz[i]=0;
G[i].clear();
}
for(int i=1;i<=m;i++){
char op;
int x,y;
cin>>op;
if(op=='U'||op=='T'||op=='F'){
cin>>x;
if(op=='U') last[x]=n+2;
else last[x]=n+1;
bz[x]=1;
}
else{
cin>>x>>y;
last[x]=last[y];
if(op=='-') bz[x]=2;
else bz[x]=1;
}
}
for(int i=1;i<=n;i++){
if(bz[i]==1){
G[last[i]].push_back(make_pair(i,0));
G[i].push_back(make_pair(last[i],0));
}
if(bz[i]==2){
G[last[i]].push_back(make_pair(i,1));
G[i].push_back(make_pair(last[i],1));
}
}
for(int i=n+1;i<=n+2;i++){
tot++;
if(i==n+1) col[i]=2;
if(i==n+2) col[i]=1;
dfs(i);
if(i==n+2){
ans+=siz[tot]-1;
}
}
for(int i=1;i<=n;i++){
if(col[i]==0){
tot++;
col[i]=2;
flag=true;
dfs(i);
if(!flag){
ans+=siz[tot];
}
}
}
cout<<ans<<endl;
}
return 0;
}
```
by Liyuqiao11 @ 2023-12-03 12:10:35