#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string.h>
using namespace std;
#define endl '\n'
#define pi pair<int, int>
#define f first
#define s second
const int maxn = 100000;
int n, m, k;
pi e[maxn];
int t[maxn], l[maxn], p[maxn], dp[maxn];
bool used[maxn], used2[maxn];
vector<pi> graph[maxn], graph2[maxn];
vector<int> b[maxn];
int s;
string ret;
void dfs2(int c){
p[c] = s;
b[s].push_back(c);
for(pi i : graph[c]){
if(p[i.f] != -1){
if(p[i.f] != -2 && p[i.f] != s){
graph2[s].push_back({p[i.f], i.s});
graph2[p[i.f]].push_back({s, i.s});
}
continue;
}
dfs2(i.f);
}
}
int x;
void dfs(int c){
used[c] = 1;
t[c] = l[c] = x++;
for(pi i : graph[c]){
if(used2[i.s]) continue;
used2[i.s] = 1;
if(used[i.f]){
l[c] = min(l[c], t[i.f]);
}else{
dfs(i.f);
l[c] = min(l[c], l[i.f]);
if(l[i.f] > t[c]){
p[c] = -2;
dfs2(i.f);
s++;
p[c] = -1;
}
}
}
if(!t[c]){
dfs2(c);
s++;
}
}
int dfs3(int c){
used[c] = 1;
for(pi i : graph2[c]){
if(used[i.f]) continue;
dp[c] += dfs3(i.f);
if(dp[i.f] < 0){
ret[i.s] = p[e[i.s].f] == c ? 'L' : 'R';
}
if(dp[i.f] > 0){
ret[i.s] = p[e[i.s].f] == c ? 'R' : 'L';
}
}
return dp[c];
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 0; i < m; i++){
cin >> e[i].f >> e[i].s;
e[i].f--, e[i].s--;
graph[e[i].f].push_back({e[i].s, i});
graph[e[i].s].push_back({e[i].f, i});
}
memset(p, -1, sizeof(p));
for(int i = 0; i < n; i++){
if(!used[i]){
x = 0;
dfs(i);
}
}
cin >> k;
for(int i = 0; i < k; i++){
int a, b;
cin >> a >> b;
a--, b--;
dp[p[a]]--;
dp[p[b]]++;
}
ret = string(m, 'B');
memset(used, 0, sizeof(used));
for(int i = 0; i < s; i++) if(!used[i]) dfs3(i);
cout << ret << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7928 KB |
Output is correct |
2 |
Correct |
10 ms |
7928 KB |
Output is correct |
3 |
Correct |
10 ms |
7928 KB |
Output is correct |
4 |
Correct |
10 ms |
8056 KB |
Output is correct |
5 |
Correct |
10 ms |
8056 KB |
Output is correct |
6 |
Correct |
10 ms |
7928 KB |
Output is correct |
7 |
Correct |
10 ms |
8056 KB |
Output is correct |
8 |
Correct |
10 ms |
8056 KB |
Output is correct |
9 |
Correct |
10 ms |
7928 KB |
Output is correct |
10 |
Correct |
10 ms |
7928 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7928 KB |
Output is correct |
2 |
Correct |
10 ms |
7928 KB |
Output is correct |
3 |
Correct |
10 ms |
7928 KB |
Output is correct |
4 |
Correct |
10 ms |
8056 KB |
Output is correct |
5 |
Correct |
10 ms |
8056 KB |
Output is correct |
6 |
Correct |
10 ms |
7928 KB |
Output is correct |
7 |
Correct |
10 ms |
8056 KB |
Output is correct |
8 |
Correct |
10 ms |
8056 KB |
Output is correct |
9 |
Correct |
10 ms |
7928 KB |
Output is correct |
10 |
Correct |
10 ms |
7928 KB |
Output is correct |
11 |
Correct |
49 ms |
14200 KB |
Output is correct |
12 |
Correct |
60 ms |
15136 KB |
Output is correct |
13 |
Correct |
70 ms |
16244 KB |
Output is correct |
14 |
Correct |
95 ms |
18292 KB |
Output is correct |
15 |
Correct |
97 ms |
18932 KB |
Output is correct |
16 |
Correct |
102 ms |
21880 KB |
Output is correct |
17 |
Correct |
94 ms |
23032 KB |
Output is correct |
18 |
Correct |
121 ms |
22008 KB |
Output is correct |
19 |
Correct |
90 ms |
24824 KB |
Output is correct |
20 |
Correct |
65 ms |
14712 KB |
Output is correct |
21 |
Correct |
60 ms |
14400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
9 ms |
7928 KB |
Output is correct |
2 |
Correct |
10 ms |
7928 KB |
Output is correct |
3 |
Correct |
10 ms |
7928 KB |
Output is correct |
4 |
Correct |
10 ms |
8056 KB |
Output is correct |
5 |
Correct |
10 ms |
8056 KB |
Output is correct |
6 |
Correct |
10 ms |
7928 KB |
Output is correct |
7 |
Correct |
10 ms |
8056 KB |
Output is correct |
8 |
Correct |
10 ms |
8056 KB |
Output is correct |
9 |
Correct |
10 ms |
7928 KB |
Output is correct |
10 |
Correct |
10 ms |
7928 KB |
Output is correct |
11 |
Correct |
49 ms |
14200 KB |
Output is correct |
12 |
Correct |
60 ms |
15136 KB |
Output is correct |
13 |
Correct |
70 ms |
16244 KB |
Output is correct |
14 |
Correct |
95 ms |
18292 KB |
Output is correct |
15 |
Correct |
97 ms |
18932 KB |
Output is correct |
16 |
Correct |
102 ms |
21880 KB |
Output is correct |
17 |
Correct |
94 ms |
23032 KB |
Output is correct |
18 |
Correct |
121 ms |
22008 KB |
Output is correct |
19 |
Correct |
90 ms |
24824 KB |
Output is correct |
20 |
Correct |
65 ms |
14712 KB |
Output is correct |
21 |
Correct |
60 ms |
14400 KB |
Output is correct |
22 |
Correct |
115 ms |
24312 KB |
Output is correct |
23 |
Correct |
114 ms |
22904 KB |
Output is correct |
24 |
Correct |
131 ms |
23092 KB |
Output is correct |
25 |
Correct |
112 ms |
27896 KB |
Output is correct |
26 |
Correct |
112 ms |
24112 KB |
Output is correct |
27 |
Correct |
122 ms |
22916 KB |
Output is correct |
28 |
Correct |
42 ms |
12152 KB |
Output is correct |
29 |
Correct |
83 ms |
15480 KB |
Output is correct |
30 |
Correct |
79 ms |
15464 KB |
Output is correct |
31 |
Correct |
88 ms |
15988 KB |
Output is correct |
32 |
Correct |
90 ms |
18944 KB |
Output is correct |