#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, 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 |
408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
412 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 |
5 ms |
724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
628 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
412 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 |
2 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
3388 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
7380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
45 ms |
3968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
544 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 |
517 ms |
28744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
442 ms |
32704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
508 ms |
35212 KB |
Memory limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
608 KB |
Output is correct |
2 |
Correct |
2 ms |
548 KB |
Output is correct |