Submission #1069385

#TimeUsernameProblemLanguageResultExecution timeMemory
1069385mariaclaraThousands Islands (IOI22_islands)C++17
1.75 / 100
26 ms8788 KiB
#include "islands.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pii; #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define pb push_back #define mk make_pair #define fr first #define sc second vector<int> ord, vis, valid; vector<vector<pii>> edges, tedges; void dfs(int x) { vis[x] = 1; for(auto [viz,ind] : edges[x]) if(!vis[viz]) dfs(viz); ord.pb(x); } void find_scc(int x) { vis[x] = 1; for(auto [viz, ind] : tedges[x]) { if(!vis[viz]) { valid[x] = valid[viz] = 1; find_scc(viz); } } } variant<bool, vector<int>> find_journey(int N, int M, vector<int> U, vector<int> V) { edges.resize(N); tedges.resize(N); vis.resize(N); valid.resize(N); for(int i = 0; i < M; i++) edges[U[i]].pb({V[i], i}), tedges[V[i]].pb({U[i], i}); //cout << "OK" << endl; for(int i = 0; i < N; i++) if(!vis[i]) dfs(i); reverse(all(ord)); vis.clear(); vis.resize(N); for(auto x : ord) if(!vis[x]) find_scc(x); // agora basta ver se tem como chegar em um no valido de 2 formas vector<vector<int>> s(N); queue<pii> fila; fila.push({0,-1}); while(!fila.empty()) { auto [x, s_e] = fila.front(); fila.pop(); if(sz(s[x]) >= 2) continue; if(sz(s[x]) == 1 and s[x][0] == s_e) continue; if(s_e != -1) s[x].pb(s_e); for(auto [viz, ind] : edges[x]) { if(s_e == -1) fila.push({viz, ind}); else fila.push({viz, s_e}); } } if(sz(edges[0]) >= 2) return vector<int>({1}); for(int i = 0; i < N; i++) if(sz(s[i]) >= 2 and valid[i]) return vector<int>({1}); return false; }
#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...