Submission #1076896

#TimeUsernameProblemLanguageResultExecution timeMemory
1076896GrayToy Train (IOI17_train)C++17
11 / 100
8 ms2652 KiB
#include "train.h" #include <bits/stdc++.h> using namespace std; #define ll int #define ff first #define ss second #define ln "\n" #define ld long double vector<ll> are; vector<ll> isc; vector<pair<ll, ll>> edge; vector<vector<ll>> A; vector<vector<ll>> rA; vector<vector<ll>> cA; vector<ll> spec; vector<ll> rspec; ll n, m; void dfs1(ll u, vector<bool> &vis, vector<ll> &ord){ vis[u]=1; for (auto i:A[u]){ ll v = edge[i].ff^edge[i].ss^u; if (!vis[v]) dfs1(v, vis, ord); } ord.push_back(u); } void dfs2(ll u, vector<ll> &comp, ll cc, ll &sz){ comp[u]=cc; sz++; if (isc[u]) spec[cc]=1; for (auto i:rA[u]){ ll v = edge[i].ff^edge[i].ss^u; if (comp[v]==-1) dfs2(v, comp, cc, sz); } } void dfs(ll u, vector<ll> &dp){ dp[u]=0; for (auto v:cA[u]){ if (dp[v]==-1) dfs(v, dp); dp[u]|=dp[v]; } if (spec[u]) dp[u]=1; } vector<int> who_wins(vector<int> a, vector<int> r, vector<int> u, vector<int> v) { n=a.size(); m=v.size(); isc=r; are=a; cA.clear(); spec.clear(); rA.clear(); rA.resize(n); A.clear(); A.resize(n); edge.clear(); edge.resize(m); rspec.clear(); rspec.resize(n); for (ll i=0; i<m; i++){ edge[i] = {u[i], v[i]}; if (u[i]==v[i]) rspec[u[i]]=1; A[u[i]].push_back(i); rA[v[i]].push_back(i); } vector<bool> vis(n); vector<ll> ord; for (ll i=0; i<n; i++){ if (!vis[i]){ dfs1(i, vis, ord); } } reverse(ord.begin(), ord.end()); vector<ll> comp(n, -1); ll cc=0; for (auto i:ord){ if (comp[i]==-1){ ll sz=0; spec.push_back(0); dfs2(i, comp, cc++, sz); if (sz==1 and !rspec[i]) spec[comp[i]]=0; } } cA.resize(cc); for (ll i=0; i<m; i++){ if (comp[edge[i].ff]!=comp[edge[i].ss]) cA[comp[edge[i].ff]].push_back(comp[edge[i].ss]); } vector<ll> dp(cc, -1); for (ll i=0; i<cc; i++){ if (dp[i]==-1) dfs(i, dp); } vector<ll> ans(n); for (ll i=0; i<n; i++){ ans[i]=dp[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...