QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#128521 | #4996. Icy Itinerary | likeblg | WA | 14ms | 52308kb | C++14 | 1.0kb | 2023-07-21 08:21:31 | 2023-07-21 08:21:35 |
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]==1)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;
}
详细
Test #1:
score: 100
Accepted
time: 8ms
memory: 50216kb
input:
4 4 1 2 1 3 1 4 3 4
output:
1 3 2 4
result:
ok qwq
Test #2:
score: 0
Accepted
time: 1ms
memory: 50868kb
input:
5 0
output:
1 2 3 4 5
result:
ok qwq
Test #3:
score: -100
Wrong Answer
time: 14ms
memory: 52308kb
input:
10 10 7 8 7 5 5 2 6 1 10 7 4 6 5 8 3 2 10 5 1 10
output:
1 8 2 3 4 5 6 7 9 10
result:
wrong answer Changed color too many times (2)