# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
130398 |
2019-07-15T06:34:15 Z |
윤교준(#3150) |
Information (CEOI08_information) |
C++14 |
|
314 ms |
12956 KB |
#include <bits/stdc++.h>
#define eb emplace_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmin(a,b) (a)=min((a),(b))
#define INF (0x3f3f3f3f)
#define INFLL (0x3f3f3f3f3f3f3f3fll)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline void fuk() { puts("NONE"); exit(0); }
const int MAXN = 2005;
const int MAXM = 1000005;
queue<int> PQ;
vector<int> G[MAXN], T[MAXN];
unordered_set<int> T1E, T1G[MAXN];
bitset<MAXM> isT1, isT2;
bitset<MAXN> isT2V, chk;
int A[MAXM], B[MAXM];
int N, M;
bool cmp(int a, int b) { return B[a] < B[b]; }
int findEdge(int i, int r, int ne) {
chk[i] = true;
B[M+1] = r;
int es = int(lower_bound(allv(G[i]), M+1, cmp) - G[i].begin());
for(int ei = es, dg = sz(G[i]), e; ei < dg; ei++) {
e = G[i][ei];
if(B[e] != r) break;
if(e != ne && !isT2[e]) return e;
}
for(int e : T1G[i]) if(e != ne) {
int v = B[e];
if(chk[v]) continue;
int ret = findEdge(v, r, ne);
if(ret) return ret;
}
return 0;
}
void makeT2() {
isT2V[1] = true;
PQ.push(1);
for(;;) {
for(int idx; !PQ.empty();) {
idx = PQ.front(); PQ.pop();
for(int e : G[idx]) {
int v = B[e];
if(isT2V[v] || isT1[e]) continue;
isT2[e] = true;
isT2V[v] = true;
PQ.push(v);
}
}
if(isT2V.count() == N) break;
for(int e : T1E) {
int a = A[e], b = B[e];
if(!isT2V[a] || isT2V[b]) continue;
chk.reset();
int ret = findEdge(1, b, e);
if(!ret) continue;
T1E.erase(e);
T1G[A[e]].erase(e);
isT1[e] = false; isT2[e] = true;
T1E.insert(ret);
T1G[A[ret]].insert(ret);
isT1[ret] = true;
isT2V[b] = true;
PQ.push(b);
break;
}
if(PQ.empty()) fuk();
}
}
void dfsT1(int i) {
chk[i] = true;
for(int e : G[i]) {
int v = B[e];
if(chk[v]) continue;
isT1[e] = true;
dfsT1(v);
}
}
void makeT1() {
dfsT1(1);
for(int i = 2; i <= N; i++) if(!chk[i]) fuk();
chk.reset();
for(int i = 1; i <= M; i++) if(isT1[i]) {
T[A[i]].eb(i);
T1E.insert(i);
T1G[A[i]].insert(i);
}
}
void prtAns() {
vector<int> V1, V2;
for(int i = 1; i <= M; i++) {
if(isT1[i] && isT2[i]) fuk();
if(isT1[i]) V1.eb(i);
if(isT2[i]) V2.eb(i);
}
if(sz(V1) != N-1 || sz(V2) != N-1) fuk();
for(int v : V1) printf("%d ", v); puts("");
for(int v : V2) printf("%d ", v); puts("");
}
int main() {
ios::sync_with_stdio(false);
cin >> N >> M;
for(int i = 1; i <= M; i++) {
cin >> A[i] >> B[i];
G[A[i]].eb(i);
}
for(int i = 1; i <= N; i++) sort(allv(G[i]), cmp);
makeT1();
makeT2();
prtAns();
return 0;
}
Compilation message
information.cpp: In function 'void makeT2()':
information.cpp:63:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(isT2V.count() == N) break;
~~~~~~~~~~~~~~^~~~
information.cpp: In function 'void prtAns()':
information.cpp:119:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int v : V1) printf("%d ", v); puts("");
^~~
information.cpp:119:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(int v : V1) printf("%d ", v); puts("");
^~~~
information.cpp:120:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
for(int v : V2) printf("%d ", v); puts("");
^~~
information.cpp:120:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
for(int v : V2) printf("%d ", v); puts("");
^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
628 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
1920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
56 ms |
3236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
2044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
636 KB |
Output is correct |
2 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
242 ms |
12900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
235 ms |
12304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
314 ms |
12956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
1016 KB |
Output is correct |
2 |
Correct |
3 ms |
632 KB |
Output is correct |