This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
bool vis[N];
vector<pii> G[N], GT[N];
void dfs(int v) {
vis[v]=true;
for (auto u : G[v]) {
if (vis[u.first]) continue;
c[u.second]=1, dfs(u.first);
}
}
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 {
bool ok=false;
for (auto z : GT[u.first]) {
if (c[z.second] == 0) {
ok=true;
c[z.second]=1;
}
}
if (ok) {
c[u.second]=2;
dfs2(u.first);
}
}
}
}
int main() {
cin>>n>>m;
for (int i=1; i<=m; ++i) {
int a, b; cin>>a>>b;
G[a].push_back({b, i});
GT[b].push_back({a, i});
}
dfs(1);
memset(vis, false, sizeof(vis));
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |