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;
bool us[M], vis[N];
vector<pii> G[N];
vector<int> l, r;
int n, m;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
void dfs(int v) {
vis[v]=true;
shuffle(G[v].begin(), G[v].end(), rng);
for (auto u : G[v]) {
if (vis[u.first]) continue;
us[u.second]=true; l.push_back(u.second);
dfs(u.first);
}
}
void dfs2(int v) {
vis[v]=true;
shuffle(G[v].begin(), G[v].end(), rng);
for (auto u : G[v]) {
if (vis[u.first] || us[u.second]) continue;
r.push_back(u.second), dfs2(u.first);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for (int i=1; i<=m; ++i) {
int a, b; cin>>a>>b;
G[a].push_back({b, i});
}
int t=100, xr=0;
while (t--) {
memset(vis, false, sizeof(vis));
dfs(1);
memset(vis, false, sizeof(vis));
dfs2(1);
xr=max(xr, (int)r.size());
if ((int)l.size() == n-1 && (int)r.size() == n-1) break;
l.clear(), r.clear();
}
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... |