# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
130464 | onjo0127 | Information (CEOI08_information) | C++11 | 227 ms | 20456 KiB |
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;
using pii = pair<int, int>;
int N, M, in[2009], ou[2009], t;
vector<pii> adj[2009], R[2009];
bool v1[2009], v2[2009];
int h[1000009];
bool isup(int u, int v) {
return in[u] <= in[v] && ou[u] >= ou[v];
}
void dfs(int x) {
in[x] = ++t;
v1[x] = 1;
for(auto& it: adj[x]) {
if(!v1[it.first]) {
h[it.second] = 1;
dfs(it.first);
}
}
ou[x] = t;
}
void go(int x) {
v2[x] = 1;
for(auto& it: adj[x]) {
int t, i; tie(t, i) = it;
if(!v2[t]) {
if(h[i] == 0) {
h[i] = 2;
go(t);
}
else if(h[i] == 1 && R[t].size()) {
int rt, ri; tie(rt, ri) = R[t].back(); R[t].pop_back();
h[i] = 2; h[ri] = 1;
go(t);
}
}
}
}
int main() {
scanf("%d%d",&N,&M);
for(int i=1; i<=M; i++) {
int u, v; scanf("%d%d",&u,&v);
adj[u].push_back({v, i});
}
dfs(1);
for(int i=1; i<=N; i++) {
for(auto& it: adj[i]) {
if(!h[it.second] && !isup(it.first, i)) R[it.first].push_back({i, it.second});
}
}
go(1);
vector<int> A1, A2;
for(int i=1; i<=N; i++) for(auto& it: adj[i]) {
if(h[it.second] == 1) A1.push_back(it.second);
if(h[it.second] == 2) A2.push_back(it.second);
}
if((int)A1.size() != N-1 || (int)A2.size() != N-1) puts("NONE");
else {
for(auto& it: A1) printf("%d ",it); puts("");
for(auto& it: A2) printf("%d ",it);
}
return 0;
}
Compilation message (stderr)
# | 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... |