Submission #628156

#TimeUsernameProblemLanguageResultExecution timeMemory
628156TurkhuuThousands Islands (IOI22_islands)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { vector<vector<pair<int, int>>> G(N); for (int i = 0; i < M; i++) { G[U[i]].emplace_back(V[i], i); } vector<int> E(N, -1), ans, R(N); function<bool(int)> dfs = [&](int A) { R[A] = 1; for (auto [B, C] : G[A]) { if (E[A] != (C ^ 1)) { if (R[B] == 1) { vector<int> a; int F = B; while (F != 0) { a.push_back(E[F]); F = U[E[F]]; } vector<int> c; int D = A; while (D != B) { c.push_back(E[D]); D = U[E[D]]; } reverse(c.begin(), c.end()); c.push_back(C); int s = c.size(); for (int i = a.size() - 1; i >= 0; i--) { ans.push_back(a[i]); } for (int i = 0; i < s; i++) { for (int j = 0; j < s; j++) { ans.push_back(c[(s - i + j) % s]); } for (int j = 0; j < s; j++) { ans.push_back(c[(s - i + j) % s] ^ 1); } } for (int i = 0; i < a.size(); i++) { ans.push_back(a[i]); } return true; } if (R[B] == 0) { E[B] = C; if (dfs(B)) { return true; } } } } R[A] = 2; return false; }; E[0] = -2; if (dfs(0)) { return ans; } else { return false; } } int main() { int N, M; assert(2 == scanf("%d %d", &N, &M)); std::vector<int> U(M), V(M); for (int i = 0; i < M; ++i) { assert(2 == scanf("%d %d", &U[i], &V[i])); } std::variant<bool, std::vector<int>> result = find_journey(N, M, U, V); if (result.index() == 0) { printf("0\n"); if (std::get<bool>(result)) { printf("1\n"); } else { printf("0\n"); } } else { printf("1\n"); std::vector<int> &canoes = std::get<std::vector<int>>(result); printf("%d\n", static_cast<int>(canoes.size())); for (int i = 0; i < static_cast<int>(canoes.size()); ++i) { if (i > 0) { printf(" "); } printf("%d", canoes[i]); } printf("\n"); } return 0; }

Compilation message (stderr)

islands.cpp: In lambda function:
islands.cpp:40:29: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |           for (int i = 0; i < a.size(); i++) {
      |                           ~~^~~~~~~~~~
/usr/bin/ld: /tmp/ccc33FKW.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccq3jUwY.o:islands.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status