QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592792#4996. Icy Itineraryship2077WA 20ms57968kbC++231.3kb2024-09-27 07:48:152024-09-27 07:48:15

Judging History

你现在查看的是最新测评结果

  • [2024-09-27 07:48:15]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:57968kb
  • [2024-09-27 07:48:15]
  • 提交

answer

#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
constexpr int M=3e5+5;
cc_hash_table<int,int>mp[M];
int n,m;vector<int>ans1,ans2;
int read(){
    int x=0;char ch=getchar();
    while (!isdigit(ch)) ch=getchar();
    while (isdigit(ch)) x=x*10+ch-48,ch=getchar();
    return x;
}
int check(int x,int y){return mp[x].find(y)!=mp[x].end();}
int main(){
    n=read();m=read();
    for (int i=1;i<=m;i++){
        int x=read(),y=read();
        mp[x][y]=mp[y][x]=1;
    }
    ans1={2};
    for (int i=3;i<=n;i++){
        int p=check(1,ans1[0]);
        if (p==check(ans1.back(),i)){
            ans1.emplace_back(i);
            if (!ans2.empty()&&p==check(i,ans2.back()))
                ans1.emplace_back(ans2.back()),ans2.pop_back();
        }
        else {
            ans2.emplace_back(ans1.back());ans1.pop_back();
            ans2.emplace_back(i);
            if (ans1.size()&&p!=check(ans1.back(),ans2.back()))
                ans1.emplace_back(ans2.back()),ans2.pop_back();
            if (!ans1.empty()) continue;
            reverse(ans2.begin(),ans2.end());
            swap(ans1,ans2);
        }
    }
    printf("1 ");
    for (auto x:ans1) printf("%d ",x);
    reverse(ans2.begin(),ans2.end());
    for (auto x:ans2) printf("%d ",x);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 20ms
memory: 57636kb

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: 19ms
memory: 57672kb

input:

5 0

output:

1 2 3 4 5 

result:

ok qwq

Test #3:

score: -100
Wrong Answer
time: 11ms
memory: 57968kb

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 3 2 4 5 6 9 8 10 7 

result:

wrong answer Changed color too many times (3)