#include <bits/stdc++.h>
#define pii pair<int, int>
#define fi first
#define se second
#define pb push_back
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define MAXN 100010
using namespace std;
int N, M, P, w[MAXN], fup[MAXN], dub[MAXN];
vector<pii> adj[MAXN];
pii edge[MAXN];
string s = "#";
void dfs(int node, int e) {
dub[node] = dub[node^edge[e].fi^edge[e].se]+1;
fup[node] = dub[node];
for(auto x : adj[node]) {
if(x.se == e) continue;
if(dub[x.fi]) {
fup[node] = min(fup[node], dub[x.fi]);
} else {
dfs(x.fi, x.se);
w[node] += w[x.fi];
fup[node] = min(fup[node], fup[x.fi]);
}
}
if(fup[node] != dub[node]) return;
if(w[node] > 0) {
int node1 = node^edge[e].fi^edge[e].se;
if(make_pair(node1, node) == edge[e]) s[e] = 'L';
else s[e] = 'R';
} else if(w[node] < 0) {
int node1 = node^edge[e].fi^edge[e].se;
if(make_pair(node1, node) == edge[e]) s[e] = 'R';
else s[e] = 'L';
}
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
cin >> N >> M;
for(int i = 1; i <= M; i++) {
int A, B; cin >> A >> B;
edge[i] = {A, B};
adj[A].pb({B, i});
adj[B].pb({A, i});
s += "B";
}
edge[0] = {1, 0};
cin >> P;
for(int i = 1; i <= P; i++) {
int X, Y; cin >> X >> Y;
w[X]++; w[Y]--;
}
for(int i = 1; i <= N; i++) {
if(!dub[i]) {
edge[0] = {i, 0};
dfs(i, 0);
}
}
for(int i = 1; i <= M; i++) cout << s[i];
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
2 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2796 KB |
Output is correct |
9 |
Correct |
2 ms |
2796 KB |
Output is correct |
10 |
Correct |
3 ms |
2796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
2 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2796 KB |
Output is correct |
9 |
Correct |
2 ms |
2796 KB |
Output is correct |
10 |
Correct |
3 ms |
2796 KB |
Output is correct |
11 |
Correct |
52 ms |
8300 KB |
Output is correct |
12 |
Correct |
53 ms |
9196 KB |
Output is correct |
13 |
Correct |
70 ms |
10360 KB |
Output is correct |
14 |
Correct |
63 ms |
10988 KB |
Output is correct |
15 |
Correct |
65 ms |
10988 KB |
Output is correct |
16 |
Correct |
67 ms |
8684 KB |
Output is correct |
17 |
Correct |
55 ms |
10732 KB |
Output is correct |
18 |
Correct |
70 ms |
8812 KB |
Output is correct |
19 |
Correct |
55 ms |
11884 KB |
Output is correct |
20 |
Correct |
46 ms |
8684 KB |
Output is correct |
21 |
Correct |
46 ms |
8428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
3 ms |
2796 KB |
Output is correct |
4 |
Correct |
2 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
2 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
2 ms |
2796 KB |
Output is correct |
9 |
Correct |
2 ms |
2796 KB |
Output is correct |
10 |
Correct |
3 ms |
2796 KB |
Output is correct |
11 |
Correct |
52 ms |
8300 KB |
Output is correct |
12 |
Correct |
53 ms |
9196 KB |
Output is correct |
13 |
Correct |
70 ms |
10360 KB |
Output is correct |
14 |
Correct |
63 ms |
10988 KB |
Output is correct |
15 |
Correct |
65 ms |
10988 KB |
Output is correct |
16 |
Correct |
67 ms |
8684 KB |
Output is correct |
17 |
Correct |
55 ms |
10732 KB |
Output is correct |
18 |
Correct |
70 ms |
8812 KB |
Output is correct |
19 |
Correct |
55 ms |
11884 KB |
Output is correct |
20 |
Correct |
46 ms |
8684 KB |
Output is correct |
21 |
Correct |
46 ms |
8428 KB |
Output is correct |
22 |
Correct |
72 ms |
10624 KB |
Output is correct |
23 |
Correct |
77 ms |
8684 KB |
Output is correct |
24 |
Correct |
90 ms |
8708 KB |
Output is correct |
25 |
Correct |
74 ms |
14188 KB |
Output is correct |
26 |
Correct |
70 ms |
10092 KB |
Output is correct |
27 |
Correct |
72 ms |
8812 KB |
Output is correct |
28 |
Correct |
38 ms |
5996 KB |
Output is correct |
29 |
Correct |
63 ms |
8172 KB |
Output is correct |
30 |
Correct |
68 ms |
8376 KB |
Output is correct |
31 |
Correct |
77 ms |
8812 KB |
Output is correct |
32 |
Correct |
66 ms |
10988 KB |
Output is correct |