QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#153725 | #6413. Classical Graph Theory Problem | 275307894a | WA | 1ms | 11460kb | C++14 | 1.7kb | 2023-08-30 19:46:25 | 2023-08-30 19:46:25 |
Judging History
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();
}
Details
Tip: Click on the bar to expand more detailed information
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)