Submission #660404

#TimeUsernameProblemLanguageResultExecution timeMemory
660404Dec0DeddInformation (CEOI08_information)C++14
100 / 100
448 ms25532 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<short, int> const int N = 2e3+1; const int M = 1e6+1; int c[M], n, m, tin[N], tout[N], t=1; bool vis[N]; vector<pii> G[N], up[N]; pii e[M]; bool anc(int v, int u) { return tin[v] <= tin[u] && tout[u] <= tout[v]; } void dfs(int v) { vis[v]=true; tin[v]=t++; for (auto u : G[v]) { if (vis[u.first]) continue; c[u.second]=1, dfs(u.first); } tout[v]=t++; } void dfs2(int v) { vis[v]=true; for (auto u : G[v]) { if (vis[u.first]) continue; if (c[u.second] == 0) { c[u.second]=2; dfs2(u.first); } else { while (up[u.first].size() > 0) { pii x=up[u.first].back(); if (c[x.second] != 0) up[u.first].pop_back(); else break; } if (!up[u.first].empty()) { c[u.second]=2, c[up[u.first].back().second]=1; up[u.first].pop_back(); dfs2(u.first); } } } } int main() { cin>>n>>m; for (int i=1; i<=m; ++i) { int a, b; cin>>a>>b; e[i]={a, b}; G[a].push_back({b, i}); } dfs(1); memset(vis, false, sizeof(vis)); for (int i=1; i<=n; ++i) { for (auto u : G[i]) { if (c[u.second] == 0 && anc(i, u.first)) up[u.first].push_back({i, u.second}); } } dfs2(1); vector<int> l, r; for (int i=1; i<=m; ++i) { if (c[i] == 1) l.push_back(i); else if (c[i] == 2) r.push_back(i); } if ((int)l.size() < n-1 || (int)r.size() < n-1) cout<<"NONE\n"; else { for (auto u : l) cout<<u<<" "; cout<<"\n"; for (auto u : r) cout<<u<<" "; cout<<"\n"; } }
#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...
#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...
#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...
#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...