QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#75345 | #4996. Icy Itinerary | WJL | WA | 0ms | 14816kb | C++14 | 1.0kb | 2023-02-04 21:28:50 | 2023-02-04 21:28:53 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=3e5+3;
int n,m,pre[N],nex[N],fen,vis[N],vis2[N];
vector<int>vec[N];
int main(){
scanf("%d%d",&n,&m);
int u,v;
for(int i=1;i<=m;i++){
scanf("%d%d",&u,&v);
vec[u].push_back(v);
vec[v].push_back(u);
}
if(!vec[1].size())nex[1]=2,pre[2]=1,fen=1,vis2[1]=1,vis2[2]=1;
else pre[vec[1][0]]=1,nex[1]=vec[1][0],fen=vec[1][0],vis2[1]=1,vis2[vec[1][0]]=1;
for(int i=1;i<=n;i++){
if(vis2[i])continue;
for(int j=0;j<(int)vec[i].size();j++){
vis[vec[i][j]]=i;
}
if(vis[fen]==i){
if(nex[fen]!=0)pre[nex[fen]]=i;
nex[i]=nex[fen];
nex[fen]=i;
pre[i]=fen;
if(vis[nex[i]]==i)fen=nex[i];
else fen=i;
}
else{
if(fen==1){
pre[nex[1]]=i;
nex[i]=nex[1];
pre[i]=1;
nex[1]=i;
}
else{
nex[pre[fen]]=i;
pre[i]=pre[fen];
pre[fen]=i;
nex[i]=fen;
if(vis[pre[i]]==i)fen=i;
else fen=pre[i];
}
}
}
int x=1;
while(x!=0){
printf("%d ",x);
x=nex[x];
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 14816kb
input:
4 4 1 2 1 3 1 4 3 4
output:
1 3 4 2
result:
ok qwq
Test #2:
score: 0
Accepted
time: 0ms
memory: 14424kb
input:
5 0
output:
1 5 4 3 2
result:
ok qwq
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 13876kb
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 10 9 8 7 5 4 3 2 6
result:
wrong answer Changed color too many times (5)