#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 time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
2704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
85 ms |
5724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
37 ms |
3224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
413 ms |
20196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
413 ms |
24628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
448 ms |
25532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
608 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |