Submission #1059667

#TimeUsernameProblemLanguageResultExecution timeMemory
1059667shiomusubi496Thousands Islands (IOI22_islands)C++17
19.25 / 100
32 ms10452 KiB
#include "islands.h" #include <bits/stdc++.h> #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define rep2(i, a, b) for (int i = (int)(a); i < (int)(b); ++i) #define rrep(i, n) for (int i = (int)(n) - 1; i >= 0; --i) #define rrep2(i, a, b) for (int i = (int)(b) - 1; i >= (int)(a); --i) #define all(v) begin(v), end(v) #define rall(v) rbegin(v), rend(v) using namespace std; using ll = long long; template<class T, class U> bool chmin(T& a, const U& b) { return a > b ? a = b, true : false; } template<class T, class U> bool chmax(T& a, const U& b) { return a < b ? a = b, true : false; } struct edge { int to, idx; }; using Graph = vector<vector<edge>>; std::variant<bool, std::vector<int>> find_journey(int N, int M, std::vector<int> U, std::vector<int> V) { Graph G(N), RG(N); rep (i, M) { G[U[i]].push_back({V[i], i}); RG[V[i]].push_back({U[i], i}); } vector<int> memo; int cur = 0; { vector<bool> seen(N, false); while (1) { seen[cur] = true; vector<edge> nxts; for (auto e : G[cur]) { if (!seen[e.to]) nxts.push_back(e); } if (nxts.size() == 0) return false; if (nxts.size() >= 2) break; memo.push_back(nxts[0].idx); cur = nxts[0].to; } } vector<int> deg(N); rep (i, M) ++deg[U[i]]; queue<int> que; rep (i, N) { if (deg[i] == 0) que.push(i); } while (!que.empty()) { int v = que.front(); que.pop(); for (auto e : RG[v]) { --deg[e.to]; if (deg[e.to] == 0) que.push(e.to); } } if (deg[cur] == 0) return false; return true; }
#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...