QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#62774 | #4996. Icy Itinerary | retaliatorElite | WA | 1ms | 3360kb | C++14 | 971b | 2022-11-20 12:01:03 | 2022-11-20 12:03:45 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
set<pair<int,int> > e;
stack<int> is,ch;
int mid;
int ans[300010];
int main(){
ios::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=m;++i){
int u,v;
cin>>u>>v;
if(u>v) swap(u,v);
e.insert(make_pair(u,v));
}
mid=1;
for(int i=2;i<=n;++i){
if(e.find(make_pair(mid,i))!=e.end()){
ch.push(mid);
mid=i;
if(is.empty()==false&&e.find(make_pair(is.top(),i))!=e.end()){
ch.push(mid);
mid=is.top();
is.pop();
}
}
else{
is.push(mid);
mid=i;
if(ch.empty()==false&&e.find(make_pair(ch.top(),i))==e.end()){
is.push(mid);
mid=ch.top();
ch.pop();
}
}
}
int tmp=is.size();
for(int i=1;i<=tmp;++i){
ans[tmp-i+1]=is.top();
is.pop();
}
ans[tmp+1]=mid;
tmp=tmp+2;
while(ch.empty()==false){
ans[tmp]=ch.top();
tmp++;
ch.pop();
}
for(int i=1;i<=n;++i){
cout<<ans[i]<<' ';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3360kb
input:
4 4 1 2 1 3 1 4 3 4
output:
2 4 3 1
result:
wrong answer The first number wasn't 1