Submission #786273

#TimeUsernameProblemLanguageResultExecution timeMemory
786273vjudge1Thousands Islands (IOI22_islands)C++17
10 / 100
30 ms5428 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { if (N == 2) { vector<int> f0, f1; for (int i = 0; i < M; i++) { (U[i] == 0 ? f0 : f1).push_back(i); } if (f0.size() < 2 || f1.size() < 1) { return false; } return vector{f0[0], f1[0], f0[1], f0[0], f1[0], f0[1]}; } bool S3 = 0; vector<vector<pair<int, int>>> adj(N); for (int i = 1; i < M; i += 2) { if (U[i - 1] != V[i] || V[i - 1] != U[i]) { S3 = 0; } adj[U[i]].emplace_back(V[i], i); adj[V[i]].emplace_back(U[i], i - 1); } if (S3) { int x = 0, y = -1; vector<int> p; while (1) { if (adj[x].size() < 2 - (y == -1)) { return false; } if (adj[x].size() > 2 - (y == -1)) { auto ans = p; int u, v; if (y == -1) { u = adj[x][0].second; v = adj[x][1].second; } else { u = adj[x][adj[x][0].second == (y ^ 1) ? 1 : 0].second; v = adj[x][adj[x][2].second == (y ^ 1) ? 1 : 2].second; } ans.push_back(u); ans.push_back(u ^ 1); ans.push_back(v); ans.push_back(v ^ 1); ans.push_back(u ^ 1); ans.push_back(u); ans.push_back(v ^ 1); ans.push_back(v); for (int i = p.size() - 1; i >= 0; i--) { ans.push_back(p[i] ^ 1); } return ans; } if (adj[x][0].second == (y ^ 1)) { tie(x, y) = adj[x][1]; } else { tie(x, y) = adj[x][0]; } p.push_back(y); } } int a, b, c, d; for (int i = 0; i < M; i++) { if (U[i] == 0) { if (V[i] == 1) { a = i; } if (V[i] == 2) { c = i; } } if (V[i] == 0) { if (U[i] == 1) { b = i; } if (U[i] == 2) { d = i; } } } return vector{a, b, c, d, b, a, d, c}; }

Compilation message (stderr)

islands.cpp: In function 'std::variant<bool, std::vector<int, std::allocator<int> > > find_journey(int, int, std::vector<int>, std::vector<int>)':
islands.cpp:81:41: warning: 'd' may be used uninitialized in this function [-Wmaybe-uninitialized]
   81 |     return vector{a, b, c, d, b, a, d, c};
      |                                         ^
islands.cpp:81:41: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:81:41: warning: 'b' may be used uninitialized in this function [-Wmaybe-uninitialized]
islands.cpp:81:41: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...