#include <bits/stdc++.h>
#define pb push_back
#define X first
#define Y second
#define pii pair<int, int>
using namespace std;
vector<vector<int>> g;
struct edge{
int u, v;
char dir;
};
vector<edge> ed;
vector<int> tin, low, val, vis;
int n, m, counter;
void dfs(int v, int p){
tin[v] = low[v] = counter;
counter++;
vis[v] = 1;
for(auto ch : g[v]){
if(ch == p)continue;
int nx = (v==ed[ch].u) ? ed[ch].v : ed[ch].u;
if(vis[nx]){
low[v] = min(low[v], tin[nx]);
continue;
}
dfs(nx, ch);
low[v] = min(low[v], low[nx]);
pii cor;
if(tin[v] < low[nx]){
if(val[nx] == 0)continue;
if(val[nx] < 0){
cor = {v, nx};
}else{
cor = {nx, v};
}
if(ed[ch].u == cor.X)ed[ch].dir = 'R';
else ed[ch].dir = 'L';
}
val[v]+=val[nx];
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
counter = 0;
g.assign(n, vector<int>());
tin.assign(n, 0);
low.assign(n, 0);
val.assign(n, 0);
vis.assign(n, 0);
for(int i = 0; i< m; i++){
int c, d; cin >> c >> d; c--; d--;
ed.pb({c, d, 'B'});
g[c].pb(i); g[d].pb(i);
}
int q; cin >> q;
while(q--){
int c, d; cin >> c >> d; c--; d--;
val[c]++; val[d]--;
}
for(int i = 0;i<n; i++){
if(!vis[i])dfs(i, -1);
}
for(auto i : ed){
cout << i.dir;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
52 ms |
5036 KB |
Output is correct |
12 |
Correct |
53 ms |
6444 KB |
Output is correct |
13 |
Correct |
63 ms |
7980 KB |
Output is correct |
14 |
Correct |
98 ms |
9644 KB |
Output is correct |
15 |
Correct |
102 ms |
10028 KB |
Output is correct |
16 |
Correct |
84 ms |
8748 KB |
Output is correct |
17 |
Correct |
81 ms |
10320 KB |
Output is correct |
18 |
Correct |
95 ms |
8736 KB |
Output is correct |
19 |
Correct |
77 ms |
11564 KB |
Output is correct |
20 |
Correct |
60 ms |
6828 KB |
Output is correct |
21 |
Correct |
52 ms |
6572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
512 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
384 KB |
Output is correct |
11 |
Correct |
52 ms |
5036 KB |
Output is correct |
12 |
Correct |
53 ms |
6444 KB |
Output is correct |
13 |
Correct |
63 ms |
7980 KB |
Output is correct |
14 |
Correct |
98 ms |
9644 KB |
Output is correct |
15 |
Correct |
102 ms |
10028 KB |
Output is correct |
16 |
Correct |
84 ms |
8748 KB |
Output is correct |
17 |
Correct |
81 ms |
10320 KB |
Output is correct |
18 |
Correct |
95 ms |
8736 KB |
Output is correct |
19 |
Correct |
77 ms |
11564 KB |
Output is correct |
20 |
Correct |
60 ms |
6828 KB |
Output is correct |
21 |
Correct |
52 ms |
6572 KB |
Output is correct |
22 |
Correct |
97 ms |
10412 KB |
Output is correct |
23 |
Correct |
92 ms |
8748 KB |
Output is correct |
24 |
Correct |
108 ms |
8760 KB |
Output is correct |
25 |
Correct |
101 ms |
13440 KB |
Output is correct |
26 |
Correct |
108 ms |
9980 KB |
Output is correct |
27 |
Correct |
91 ms |
8876 KB |
Output is correct |
28 |
Correct |
36 ms |
2744 KB |
Output is correct |
29 |
Correct |
78 ms |
6572 KB |
Output is correct |
30 |
Correct |
74 ms |
6524 KB |
Output is correct |
31 |
Correct |
80 ms |
6828 KB |
Output is correct |
32 |
Correct |
79 ms |
9256 KB |
Output is correct |