제출 #809893

#제출 시각아이디문제언어결과실행 시간메모리
809893qwerasdfzxcl열쇠 (IOI21_keys)C++17
9 / 100
306 ms67120 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; vector<pair<int, int>> adj[300300], st[300300]; vector<int> nxt[300300]; int col[300300], dfn[300300], INV[300300], mn[300300], out[300300], cnt = 1; bool visited[300300]; void dfs(int s, int pa = -1){ dfn[s] = cnt++; INV[dfn[s]] = s; visited[s] = 1; mn[s] = dfn[s]; out[s] = dfn[s]; ///stack push for (auto &[c, v]:adj[s]) st[c].emplace_back(s, v); ///stack pop for (auto &[u, v]:st[col[s]]) nxt[u].push_back(v); st[col[s]].clear(); ///traverse while(!nxt[s].empty()){ int v = nxt[s].back(); nxt[s].pop_back(); if (visited[v]) {mn[s] = min(mn[s], mn[v]); continue;} dfs(v, s); mn[s] = min(mn[s], mn[v]); out[s] = out[v]; ///stack pop for (auto &[u, v]:st[col[s]]) nxt[u].push_back(v); st[col[s]].clear(); } } std::vector<int> find_reachable(std::vector<int> r, std::vector<int> u, std::vector<int> v, std::vector<int> c) { std::vector<int> ans(r.size()); int n = r.size(); ///build graph for (int i=1;i<=n;i++){ col[i] = r[i-1]; } for (int i=0;i<(int)u.size();i++){ adj[u[i]+1].emplace_back(c[i], v[i]+1); adj[v[i]+1].emplace_back(c[i], u[i]+1); } /// for (int i=1;i<=n;i++) if (!visited[i]) dfs(i); int rans = 1e9; for (int i=1;i<=n;i++) if (mn[i]==dfn[i]) rans = min(rans, out[i] - dfn[i] + 1); for (int i=1;i<=n;i++) if (mn[i]==dfn[i] && out[i]-dfn[i]+1==rans){ for (int j=dfn[i];j<=out[i];j++) ans[INV[j]-1] = 1; } 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...