제출 #710713

#제출 시각아이디문제언어결과실행 시간메모리
710713Jarif_Rahman수천개의 섬 (IOI22_islands)C++17
35 / 100
463 ms46568 KiB
#include "islands.h" #include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; int n, m, k; vector<int> U, V; vector<vector<int>> initial_graph; vector<bool> reachable; vector<set<int>> in(n), out(n); set<pair<int, int>> st; void dfs_reachability(int nd){ if(reachable[nd]) return; reachable[nd] = 1; for(int x: initial_graph[nd]) dfs_reachability(x); } void remove_node(int nd){ st.erase({out[nd].size(), nd}); for(int i: in[nd]){ st.erase({out[U[i]].size(), U[i]}); out[U[i]].erase(i); st.insert({out[U[i]].size(), U[i]}); } for(int i: out[nd]) in[V[i]].erase(i); out[nd].clear(); in[nd].clear(); } void preprocess(){ in.resize(n); out.resize(n); for(int i = 0; i < m; i++){ if(!reachable[U[i]] || !reachable[V[i]]) continue; out[U[i]].insert(i); in[V[i]].insert(i); } for(int i = 0; i < n; i++){ st.insert({out[i].size(), i}); } while(!st.empty() && st.begin()->f == 0) remove_node(st.begin()->sc); }; variant<bool, vector<int>> find_journey(int _n, int _m, vector<int> _U, vector<int> _V){ n = _n, m = _m, U = _U, V = _V; initial_graph.assign(n, {}); reachable.assign(n, 0); for(int i = 0; i < m; i++) initial_graph[U[i]].pb(V[i]); dfs_reachability(0); preprocess(); set<int> cur = {0}; int ND = -1; while(!cur.empty()){ for(int x: cur){ if(out[x].size() >= 2) ND = x; } if(ND != -1) break; set<int> _cur; for(int x: cur) for(int i: out[x]) _cur.insert(V[i]); for(int x: cur) remove_node(x); while(!st.empty() && st.begin()->f == 0) remove_node(st.begin()->sc); swap(cur, _cur); } if(ND == -1) 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...