제출 #674068

#제출 시각아이디문제언어결과실행 시간메모리
674068US3RN4M3수천개의 섬 (IOI22_islands)C++17
10.15 / 100
1085 ms18460 KiB
#include"islands.h" #include<vector> #include<algorithm> #include<iostream> using namespace std; using ll = long long; const int mx = 200005; vector<pair<int, int>> fwd[mx]; vector<pair<int, int>> bck[mx]; int vis[mx]; bool is_cycle[mx]; int N; void dfs1(int cur) { vis[cur] = 1; for(auto [nxt, id] : fwd[cur]) { if(vis[nxt] == 0) dfs1(nxt); else if(vis[nxt] == 1) { is_cycle[cur] = true; } } vis[cur] = 2; } bool test(int bit) { { for(int i = 0; i < N; i++) vis[i] = 0; vector<int> q; for(auto [nxt, id] : fwd[0]) { if((id >> bit) & 1) continue; q.push_back(nxt); vis[nxt] = 1; } bool cond = false; int qidx = 0; while(qidx < q.size()) { int cur = q[qidx++]; if(is_cycle[cur]) cond = true; for(auto [nxt, id] : fwd[cur]) { if(!vis[nxt]) { q.push_back(nxt); vis[nxt] = 1; } } } if(!cond) return false; } { for(int i = 0; i < N; i++) vis[i] = 0; vector<int> q; for(auto [nxt, id] : fwd[0]) { if(!((id >> bit) & 1)) continue; q.push_back(nxt); vis[nxt] = 1; } bool cond = false; int qidx = 0; while(qidx < q.size()) { int cur = q[qidx++]; if(is_cycle[cur]) cond = true; for(auto [nxt, id] : fwd[cur]) { if(!vis[nxt]) { q.push_back(nxt); vis[nxt] = 1; } } } if(!cond) return false; } return true; } std::variant<bool, std::vector<int>> find_journey(int _N, int M, std::vector<int> U, std::vector<int> V) { N = _N; for(int i = 0; i < N; i++) { fwd[i].clear(); bck[i].clear(); vis[i] = 0; } for(int i = 0; i < M; i++) { fwd[U[i]].push_back({V[i], i}); bck[V[i]].push_back({U[i], i}); } dfs1(0); for(int bit = 0; bit < 20; bit++) { if(test(bit)) return vector<int>(1, 2); } return false; }

컴파일 시 표준 에러 (stderr) 메시지

islands.cpp: In function 'bool test(int)':
islands.cpp:34:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   while(qidx < q.size()) {
      |         ~~~~~^~~~~~~~~~
islands.cpp:56:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   while(qidx < q.size()) {
      |         ~~~~~^~~~~~~~~~
#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...