#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> ii;
ii edges[100005];
int p[100005];
int label[100005];
int edgeId[100005];
vector<ii> adj[100005];
bool isBridge[100005];
int low[100005];
int depth[100005];
bool pathCompressed[100005];
void tarjan(int u){
low[u] = depth[u];
for(ii e : adj[u]){
int v = e.first, id = e.second;
if(depth[v] == 0){
p[v] = u;
depth[v] = depth[u] + 1;
tarjan(v);
if(low[v] > depth[u]) isBridge[id] = true;
low[u] = min(low[u], low[v]);
edgeId[v] = id;
}
else if(v != p[u]) low[u] = min(low[u], depth[v]);
}
}
int component[100005];
int cnt = 1;
void compress(int s){
component[s] = cnt;
for(ii e : adj[s]){
int v = e.first, id = e.second;
if(component[v] == 0 && !isBridge[id]){
compress(v);
}
}
}
int ans[100005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1;i <= m;i++){
int a, b; cin >> a >> b;
edges[i] = ii(a, b);
adj[a].push_back(ii(b,i));
adj[b].push_back(ii(a,i));
}
for(int i = 1;i <= n;i++){
if(depth[i] != 0) continue;
depth[i] = 1;
tarjan(i);
}
for(int i = 1;i <= n;i++){
if(component[i] != 0) continue;
compress(i);
cnt++;
}
for(int i = 1;i <= m;i++){
if(isBridge[i]){
int a = edges[i].first, b = edges[i].second;
if(component[a] == component[b]) isBridge[i] = false;
}
}
int Q; cin >> Q;
while(Q--){
int s, t; cin >> s >> t;
int labelS = 1, labelT = 2;
vector<int> nodes;
while(s != t){
if(depth[s] >= depth[t]){
if(!pathCompressed[s]) label[s] = labelS;
pathCompressed[s] = true;
nodes.push_back(s);
s = p[s];
}
else{
if(!pathCompressed[t]) label[t] = labelT;
pathCompressed[t] = true;
nodes.push_back(t);
t = p[t];
}
}
int P = s;
for(int x : nodes) p[x] = P;
}
for(int i = 1;i <= n;i++){
int e = edgeId[i];
if(e == 0) continue;
int a = edges[e].first;
int b = edges[e].second;
bool swapped = false;
if(depth[a] > depth[b]){
swap(a, b);
swapped = true;
}
int ANS = label[b];
if(ANS == 0) continue;
if(swapped) ANS = 3 - ANS;
ans[e] = ANS;
}
string S = "BLR";
for(int i = 1;i <= m;i++){
if(!isBridge[i]) ans[i] = 0;
cout << S[ans[i]];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
8 ms |
2816 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
9 |
Correct |
6 ms |
2816 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
8 ms |
2816 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
9 |
Correct |
6 ms |
2816 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
11 |
Correct |
51 ms |
8824 KB |
Output is correct |
12 |
Correct |
55 ms |
9720 KB |
Output is correct |
13 |
Correct |
60 ms |
10928 KB |
Output is correct |
14 |
Correct |
83 ms |
11896 KB |
Output is correct |
15 |
Correct |
83 ms |
12208 KB |
Output is correct |
16 |
Correct |
68 ms |
10256 KB |
Output is correct |
17 |
Correct |
76 ms |
12132 KB |
Output is correct |
18 |
Correct |
70 ms |
10744 KB |
Output is correct |
19 |
Correct |
62 ms |
12920 KB |
Output is correct |
20 |
Correct |
60 ms |
9696 KB |
Output is correct |
21 |
Correct |
55 ms |
9592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2688 KB |
Output is correct |
2 |
Correct |
6 ms |
2816 KB |
Output is correct |
3 |
Correct |
8 ms |
2816 KB |
Output is correct |
4 |
Correct |
6 ms |
2816 KB |
Output is correct |
5 |
Correct |
7 ms |
2816 KB |
Output is correct |
6 |
Correct |
6 ms |
2816 KB |
Output is correct |
7 |
Correct |
7 ms |
2816 KB |
Output is correct |
8 |
Correct |
6 ms |
2816 KB |
Output is correct |
9 |
Correct |
6 ms |
2816 KB |
Output is correct |
10 |
Correct |
6 ms |
2816 KB |
Output is correct |
11 |
Correct |
51 ms |
8824 KB |
Output is correct |
12 |
Correct |
55 ms |
9720 KB |
Output is correct |
13 |
Correct |
60 ms |
10928 KB |
Output is correct |
14 |
Correct |
83 ms |
11896 KB |
Output is correct |
15 |
Correct |
83 ms |
12208 KB |
Output is correct |
16 |
Correct |
68 ms |
10256 KB |
Output is correct |
17 |
Correct |
76 ms |
12132 KB |
Output is correct |
18 |
Correct |
70 ms |
10744 KB |
Output is correct |
19 |
Correct |
62 ms |
12920 KB |
Output is correct |
20 |
Correct |
60 ms |
9696 KB |
Output is correct |
21 |
Correct |
55 ms |
9592 KB |
Output is correct |
22 |
Correct |
116 ms |
12796 KB |
Output is correct |
23 |
Correct |
106 ms |
10616 KB |
Output is correct |
24 |
Correct |
126 ms |
10676 KB |
Output is correct |
25 |
Correct |
107 ms |
14348 KB |
Output is correct |
26 |
Correct |
106 ms |
11640 KB |
Output is correct |
27 |
Correct |
99 ms |
10616 KB |
Output is correct |
28 |
Correct |
51 ms |
6392 KB |
Output is correct |
29 |
Correct |
94 ms |
9208 KB |
Output is correct |
30 |
Correct |
89 ms |
9340 KB |
Output is correct |
31 |
Correct |
95 ms |
9592 KB |
Output is correct |
32 |
Correct |
104 ms |
11304 KB |
Output is correct |