QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#128242#4996. Icy ItineraryHanx16MsgrWA 1ms3520kbC++141.1kb2023-07-20 19:18:082023-07-20 19:18:09

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 19:18:09]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3520kb
  • [2023-07-20 19:18:08]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int _N = 3e5 + 5;
int n, m;
map<pair<int, int>, bool> H;
void AddEdge(int x, int y) { H[{x, y}] = H[{y, x}] = 1; }
bool Check(int x, int y) { return H.count({x, y}); }
signed main() {
   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   cin >> n >> m;
   for (int i = 1, x, y; i <= m; ++i)
      cin >> x >> y, AddEdge(x, y);
   vector<int> q1, q2;
   q1.emplace_back(1), q2.emplace_back(2);
   for (int i = 3; i <= n; ++i) {
      int x = -1, y = -1;
      if (!q1.empty()) x = q1.back();
      else { q1.emplace_back(i); continue; }
      if (!q2.empty()) y = q2.back();
      else { q2.emplace_back(i); continue; }
      if (Check(i, x)) q1.emplace_back(i);
      else if (!Check(i, y)) q2.emplace_back(i);
      else {
         if (Check(x, y)) {
            q2.pop_back();
            q1.emplace_back(y);
            q1.emplace_back(i);
         } else {
            q1.pop_back();
            q2.emplace_back(x);
            q2.emplace_back(i);
         }
      }
   }
   for (int x : q1) cout << x << ' ';
   for (int x : q2) cout << x << ' ';
   cout << '\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3484kb

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: 3452kb

input:

5 0

output:

1 2 3 4 5 

result:

ok qwq

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3520kb

input:

10 10
7 8
7 5
5 2
6 1
10 7
4 6
5 8
3 2
10 5
1 10

output:

9 2 1 3 5 6 7 4 8 10 

result:

wrong answer The first number wasn't 1