#include <bits/stdc++.h>
#define maxn 100005
using namespace std;
int n,m;
vector<pair<int,int> > a[maxn];
int disc[maxn];
int low[maxn];
int ct=1;
int l[maxn];
int r[maxn];
char s[maxn];
void dfs(int u,int p=-1,int pi=-1) {
disc[u]=low[u]=ct++;
for(auto vt:a[u]) {
int v=vt.first;
int i=vt.second;
if(disc[v]==0) {
dfs(v,u,i);
low[u]=min(low[u],low[v]);
l[u]+=l[v];
r[u]+=r[v];
if(low[v]>disc[u]) {
if(i>0) {
if(l[v]>r[v]) s[i]='L';
if(l[v]<r[v]) s[i]='R';
}
else {
if(l[v]>r[v]) s[-i]='R';
if(l[v]<r[v]) s[-i]='L';
}
}
}
else {
if(i+pi!=0) low[u]=min(low[u],disc[v]);
}
}
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(false);
cin>>n>>m;
for(int i=1;i<=m;i++) {
int u,v;
cin>>u>>v;
a[u].push_back({v,i});
a[v].push_back({u,-i});
s[i]='B';
}
int p;
cin>>p;
for(int i=0;i<p;i++) {
int u,v;
cin>>u>>v;
l[u]++;
r[v]++;
}
for(int i=1;i<=n;i++) {
if(disc[i]==0) dfs(i,-1,-1);
}
cout<<s+1<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4200 KB |
Output is correct |
4 |
Correct |
1 ms |
4188 KB |
Output is correct |
5 |
Correct |
1 ms |
4188 KB |
Output is correct |
6 |
Correct |
1 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
4188 KB |
Output is correct |
8 |
Correct |
1 ms |
4184 KB |
Output is correct |
9 |
Correct |
1 ms |
4188 KB |
Output is correct |
10 |
Correct |
1 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4200 KB |
Output is correct |
4 |
Correct |
1 ms |
4188 KB |
Output is correct |
5 |
Correct |
1 ms |
4188 KB |
Output is correct |
6 |
Correct |
1 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
4188 KB |
Output is correct |
8 |
Correct |
1 ms |
4184 KB |
Output is correct |
9 |
Correct |
1 ms |
4188 KB |
Output is correct |
10 |
Correct |
1 ms |
4188 KB |
Output is correct |
11 |
Correct |
21 ms |
8276 KB |
Output is correct |
12 |
Correct |
25 ms |
9048 KB |
Output is correct |
13 |
Correct |
22 ms |
9820 KB |
Output is correct |
14 |
Correct |
28 ms |
10180 KB |
Output is correct |
15 |
Correct |
26 ms |
10076 KB |
Output is correct |
16 |
Correct |
26 ms |
8216 KB |
Output is correct |
17 |
Correct |
24 ms |
9820 KB |
Output is correct |
18 |
Correct |
24 ms |
8068 KB |
Output is correct |
19 |
Correct |
21 ms |
10952 KB |
Output is correct |
20 |
Correct |
18 ms |
8424 KB |
Output is correct |
21 |
Correct |
19 ms |
8280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4188 KB |
Output is correct |
3 |
Correct |
1 ms |
4200 KB |
Output is correct |
4 |
Correct |
1 ms |
4188 KB |
Output is correct |
5 |
Correct |
1 ms |
4188 KB |
Output is correct |
6 |
Correct |
1 ms |
4188 KB |
Output is correct |
7 |
Correct |
1 ms |
4188 KB |
Output is correct |
8 |
Correct |
1 ms |
4184 KB |
Output is correct |
9 |
Correct |
1 ms |
4188 KB |
Output is correct |
10 |
Correct |
1 ms |
4188 KB |
Output is correct |
11 |
Correct |
21 ms |
8276 KB |
Output is correct |
12 |
Correct |
25 ms |
9048 KB |
Output is correct |
13 |
Correct |
22 ms |
9820 KB |
Output is correct |
14 |
Correct |
28 ms |
10180 KB |
Output is correct |
15 |
Correct |
26 ms |
10076 KB |
Output is correct |
16 |
Correct |
26 ms |
8216 KB |
Output is correct |
17 |
Correct |
24 ms |
9820 KB |
Output is correct |
18 |
Correct |
24 ms |
8068 KB |
Output is correct |
19 |
Correct |
21 ms |
10952 KB |
Output is correct |
20 |
Correct |
18 ms |
8424 KB |
Output is correct |
21 |
Correct |
19 ms |
8280 KB |
Output is correct |
22 |
Correct |
33 ms |
9820 KB |
Output is correct |
23 |
Correct |
34 ms |
8180 KB |
Output is correct |
24 |
Correct |
36 ms |
8276 KB |
Output is correct |
25 |
Correct |
33 ms |
12588 KB |
Output is correct |
26 |
Correct |
32 ms |
9296 KB |
Output is correct |
27 |
Correct |
35 ms |
8192 KB |
Output is correct |
28 |
Correct |
16 ms |
6516 KB |
Output is correct |
29 |
Correct |
30 ms |
8132 KB |
Output is correct |
30 |
Correct |
31 ms |
8224 KB |
Output is correct |
31 |
Correct |
33 ms |
8528 KB |
Output is correct |
32 |
Correct |
30 ms |
10324 KB |
Output is correct |