QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#128520 | #4996. Icy Itinerary | likeblg | WA | 4ms | 51096kb | C++14 | 1.0kb | 2023-07-21 08:20:48 | 2023-07-21 08:20:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int const N=1e6+10;
map<int,int>G[N];
int pa1[N],pa2[N],n,m,cnt1,cnt2;
int main(){
cin>>n>>m;
if(m==0){
for(int i=1;i<=n;i++)cout<<i<<" ";
return 0;
}
for(int i=1;i<=m;i++){
int x,y;
cin>>x>>y;
G[x][y]=1;
G[y][x]=1;
}
pa1[1]=1;cnt1=1;
for(int i=2;i<=n;i++){
if(G[i][pa1[cnt1]])pa1[++cnt1]=i;
else{
if(!G[i][pa2[cnt2]])pa2[++cnt2]=i;
else{
if(G[pa1[cnt1]][pa2[cnt2]]){
pa1[++cnt1]=pa2[cnt2];
pa1[++cnt1]=i;
cnt2--;
}
else{
if(cnt1){
pa2[++cnt2]=pa1[cnt1];
pa2[++cnt2]=i;
cnt1--;
}
else{
pa1[++cnt1]=i;
}
}
}
}
}
int flag=1;
for(int i=1;i<=cnt2;i++){
if(pa2[i]==i)flag=2;
}
if(flag==1){
for(int i=1;i<=cnt1;i++)cout<<pa1[i]<<" ";
for(int i=1;i<=cnt2;i++)cout<<pa2[i]<<" ";
}
else{
cout<<"1 ";
for(int i=1;i<=cnt1;i++)cout<<pa1[i]<<" ";
for(int i=1;i<=cnt2;i++)if(pa2[i]!=1)cout<<pa2[i]<<" ";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 4ms
memory: 51096kb
input:
4 4 1 2 1 3 1 4 3 4
output:
1 1 3 2 4
result:
wrong answer Visited the same node multiple times