QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#130878 | #4996. Icy Itinerary | cztq | RE | 1ms | 5860kb | C++14 | 982b | 2023-07-25 16:06:54 | 2023-07-25 16:06:58 |
Judging History
answer
#include<bits/stdc++.h>
#define N 300010
using namespace std;
struct edge{
int v,ne;
}e[N<<1];
int n,m,cnt,h[N];
deque<int>q1,q2;
void add(int u,int v){
e[++cnt].v = v;
e[cnt].ne = h[u];
h[u] = cnt;
}
bool check(int u,int v){
for(int i = h[u];i;i = e[i].ne)
if(e[i].v==v) return true;
return false;
}
int main(){
scanf("%d%d",&n,&m);
for(int i = 1;i<=m;i++){
int u,v;
scanf("%d%d",&u,&v);
add(u,v);add(v,u);
}
q1.push_back(1);
q2.push_back(2);
for(int i = 3;i<=n;i++){
if(check(i,q1.back())){
q1.push_back(i);
}else if(check(q2.back(),i)){
if(check(q1.back(),q2.back())){
q1.push_back(q2.back());
q2.pop_back();
q1.push_back(i);
}else{
q2.push_back(q1.back());
q1.pop_back();
q2.push_back(i);
}
}else q2.push_back(i);
}
while(q1.size()){
printf("%d ",q1.front());
q1.pop_front();
}
while(q2.size()){
printf("%d ",q2.front());
q2.pop_front();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5812kb
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: 1ms
memory: 5860kb
input:
5 0
output:
1 2 3 4 5
result:
ok qwq
Test #3:
score: -100
Runtime Error
input:
10 10 7 8 7 5 5 2 6 1 10 7 4 6 5 8 3 2 10 5 1 10