QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#153725#6413. Classical Graph Theory Problem275307894aWA 1ms11460kbC++141.7kb2023-08-30 19:46:252023-08-30 19:46:25

Judging History

你现在查看的是最新测评结果

  • [2023-08-30 19:46:25]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11460kb
  • [2023-08-30 19:46:25]
  • 提交

answer

#include<bits/stdc++.h>
#define R(n) (rnd()%(n)+1)
#define LB lower_bound
#define PB push_back
#define fi first
#define se second
#define Me(x,y) memset(x,y,sizeof x)
using namespace std;
using ll=long long;
const int N=2e5+5,mod=1e9+7;
int n,m,k,x,y,z,Sum,vis[N],col[N],f[N],Si[N],In[N];vector<int> S[N];
void Make(int x){
    vis[x]=1;for(int i:S[x]) if(!vis[i]){
        In[i]--;if(In[i]==1) for(int j:S[i]) if(!vis[j]) Si[j]++;
    }
    vector<pair<int,int> > P;
    for(int i:S[x]) if(!vis[i]&&In[i]==1){
        int To;for(int j:S[i]) if(!vis[j]) To=j;
        if(Si[To]>2) vis[i]=1,Si[To]--,P.PB({i,To});
    }
    int Ts=0;
    cerr<<'x'<<x<<'\n';
    for(auto i:P) cerr<<i.se<<'\n';
    for(auto i:P) if(!vis[i.se]) Make(i.se);
    for(auto i:P) Ts+=col[i.se];
    int PP=1;for(int i:S[x]) if(!In[i]&&!vis[i]) PP--;
    if(Ts<0) col[x]=1;else if(Ts>0) col[x]=1;
    else if(Sum>0) col[x]=-PP;else col[x]=PP;
    Sum+=col[x];
    for(int i:S[x]) if(!In[i]&&!vis[i]) col[i]=-col[x],Sum+=col[i];
    for(auto i:P) {
        if(col[i.se]==col[x]) col[i.fi]=-col[x];
        else if(Sum>0) col[i.fi]=-1;else col[i.fi]=1;
        Sum+=col[i.fi];
    }
}
void Solve(){
    int i,j;scanf("%d%d",&n,&m);for(i=1;i<=n;i++) In[i]=col[i]=vis[i]=0,S[i].clear();Sum=0;
    while(m--) scanf("%d%d",&x,&y),S[x].PB(y),S[y].PB(x),In[x]++,In[y]++;
    if(n<=2) {if(n==2) printf("1 ");printf("\n");return;}
    for(i=1;i<=n;i++) if(S[i].size()==1) for(int j:S[i]) Si[j]++;
    for(i=1;i<=n;i++) if(In[i]^1&&!vis[i]) Make(i);
    for(i=1;i<=n;i++) if(Sum==-1) ~col[i]&&(printf("%d ",i));else !~col[i]&&(printf("%d ",i));
    printf("\n");
}
int main(){
    int t;scanf("%d",&t);while(t--) Solve();
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 11460kb

input:

2
6 7
1 2
1 3
2 3
3 4
4 5
4 6
5 6
3 2
1 2
2 3

output:

4 
2 3 

result:

wrong output format Unexpected end of file - int32 expected (test case 2)