제출 #776756

#제출 시각아이디문제언어결과실행 시간메모리
776756SanguineChameleon수천개의 섬 (IOI22_islands)C++17
35 / 100
92 ms18024 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; const int maxN = 1e5 + 20; vector<pair<int, int>> adj1[maxN]; vector<pair<int, int>> adj2[maxN]; int deg[maxN]; bool rem[maxN]; variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { for (int i = 0; i < M; i++) { adj1[U[i]].emplace_back(V[i], i); adj2[V[i]].emplace_back(U[i], i); deg[U[i]]++; } deque<int> Q; for (int i = 0; i < N; i++) { if (deg[i] == 0) { rem[i] = true; Q.push_back(i); } } vector<int> res; int start = 0; pair<int, int> nxt1, nxt2; while (true) { while (!Q.empty()) { int u = Q.front(); Q.pop_front(); for (auto e: adj2[u]) { int v = e.first; if (rem[v]) { continue; } deg[v]--; if (deg[v] == 0) { rem[v] = true; Q.push_back(v); } } } if (rem[start]) { return false; } nxt1 = {-1, -1}; nxt2 = {-1, -1}; for (auto e: adj1[start]) { if (!rem[e.first]) { if (nxt1.first == -1) { nxt1 = e; } else if (nxt2.first == -1) { nxt2 = e; } } } if (nxt1.first == -1) { return false; } if (nxt2.first == -1) { rem[start] = true; Q.push_back(start); start = nxt1.first; } else { break; } } 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...