Submission #1304677

#TimeUsernameProblemLanguageResultExecution timeMemory
1304677FaggiToy Train (IOI17_train)C++20
0 / 100
9 ms7744 KiB
#include <bits/stdc++.h> #define ll long long #define sz(x) int(x.size()) #define forn(i, n) for (i = 0; i < n; i++) #define all(x) x.begin(), x.end() #define pb push_back #define mp make_pair #define fr first #define se second using namespace std; const int MAXN = 1e5 + 1; vector<ll> grafo[MAXN], grafoINV[MAXN], topo; set<ll>gComps[MAXN]; bool vis[MAXN], act[MAXN]; ll comp[MAXN], actC, ap[MAXN]; vector<int> ans, A, R; void dfs(ll nod) { vis[nod]=1; for (auto k : grafo[nod]) { if (vis[k]) continue; dfs(k); } topo.pb(nod); } void dfs2(ll nod) { comp[nod]=actC; if(R[nod]) act[actC]=1; for(auto k:grafoINV[nod]) { if(comp[k]) continue; dfs2(k); } } bool dfs3(ll nod) { vis[nod]=1; for(auto k:gComps[nod]) { if(!vis[k]) act[nod]=act[nod]|dfs3(k); else act[nod]=act[nod]|act[k]; } return act[nod]; } std::vector<int> who_wins(std::vector<int> a, std::vector<int> r, std::vector<int> u, std::vector<int> v) { ll i, n = sz(a), m = sz(u); A = a; R = r; ans.resize(n, 0); for (i = 0; i < m; i++) { grafo[u[i]].pb(v[i]); grafoINV[v[i]].pb(u[i]); } for (i = 0; i < n; i++) if(vis[i]==0) dfs(i); reverse(all(topo)); for(i=0; i<sz(topo); i++) if(!comp[topo[i]]) { actC++; dfs2(topo[i]); } for(i=0; i<n; i++) for(auto k:grafo[i]) if(comp[i]!=comp[k]) { gComps[comp[i]].insert(comp[k]); ap[comp[k]]; } memset(vis,0,sizeof(vis)); for(i=1; i<=actC; i++) if(!ap[i]) dfs3(i); for(i=0; i<n; i++) ans[i]=act[comp[i]]; return ans; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...