#include<bits/stdc++.h>
using namespace std;
const int N = 100010;
vector <pair <int, int>> g[N];
vector <pair <int, int>> backedges[N];
int l[N], r[N];
int mark[N];
set <array <int, 3>> edges;
vector <array <int, 3>> arestas;
int tin[N], low[N], pai[N];
int tmm = 1;
char res[N];
map <pair <int,int>, int> look;
int aux[N];
int sz[N];
void dfs3(int v, int p){
int val = -1;
aux[v] = 1;
sz[v] = l[v]-r[v];
for(auto [x, i] : g[v]){
if(x == p){
val = i;
look[{x, v}] = look[{v, x}] = i;
continue;
}
dfs3(x, v);
sz[v] += sz[x];
}
if(val == -1) return;
if(res[val] == 'B') return;
if(sz[v] == 0){
res[val] = 'B';
}
else if(sz[v] > 0){
res[val] = 'U';
}
else{
res[val] = 'D';
}
}
void dfs2(int v, int p){
pai[v] = p;
tin[v] = tmm;
tmm++;
low[v] = tin[v];
for(auto [x,i] : backedges[v]){
if(tin[x] == 0) continue;
low[v] = min(low[v], tin[x]);
}
for(auto [x,i] : g[v]){
if(x == p) {
look[{x, v}] = look[{v, x}] = i;
continue;
}
dfs2(x,v);
low[v] = min(low[v], low[x]);
}
tmm++;
return;
}
void dfs(int v, int p){
mark[v] = 1;
for(auto [x, i] : g[v]){
if(x == p) continue;
if(mark[x] == 1) continue;
edges.insert({v, x, i});
edges.insert({x, v, i});
dfs(x, v);
}
return;
}
map <pair <int, int>, int> buceta;
int main(){
int n, m;
cin >> n >> m;
for(int i = 0;i < m;i++){
int a, b;
cin >> a >> b;
g[a].push_back({b, i});
g[b].push_back({a, i});
arestas.push_back({a, b, i});
look[{a, b}] = i;
look[{b, a}] = i;
buceta[{a, b}] = 0;
buceta[{b, a}] = 1;
}
int q;
cin >> q;
while(q--){
int a, b;cin >> a >> b;
l[a]++;
r[b]++;
}
for(int i = 1;i <= n;i++){
if(mark[i] == 0) dfs(i, i);
}
for(int i = 1;i <= n;i++) g[i].clear();
for(auto [a, b, i] : edges){
g[a].push_back({b, i});
}
for(auto [a, b, i] : arestas){
if(edges.find({a, b, i}) != edges.end() or edges.find({b, a, i}) != edges.end()) continue;
backedges[a].push_back({b, i});
backedges[b].push_back({a, i});
res[i] = 'B';
}
for(int i = 1;i <= n;i++){
if(pai[i] == 0){
dfs2(i, i);
}
}
for(int i = 1;i <= n;i++){
if(i == pai[i]) continue;
if(low[i] <= tin[pai[i]]){
int t = look[{i, pai[i]}];
res[t] = 'B';
}
}
for(int i = 1;i <= n;i++){
if(aux[i] == 0) dfs3(i, i);
}
for(int i = 1;i <= n;i++){
if(i == pai[i]) continue;
int val = look[{i, pai[i]}];
if(res[val] == 'B') continue;
if(buceta[{i, pai[i]}] == 0){
if(res[val] == 'U') res[val] = 'R';
else res[val] = 'L';
}
else{
if(res[val] == 'U') res[val] = 'L';
else res[val] = 'R';
}
}
//cout << m << '\n';
for(int i = 0;i < m;i++){
cout << res[i];
if(res[i] != 'B' and res[i] != 'L' and res[i] != 'R') return 1;
}
cout << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8016 KB |
Output is correct |
2 |
Correct |
2 ms |
8016 KB |
Output is correct |
3 |
Correct |
4 ms |
8548 KB |
Output is correct |
4 |
Correct |
4 ms |
8528 KB |
Output is correct |
5 |
Correct |
4 ms |
8696 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
5 ms |
8528 KB |
Output is correct |
8 |
Correct |
5 ms |
8528 KB |
Output is correct |
9 |
Correct |
4 ms |
8528 KB |
Output is correct |
10 |
Correct |
4 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8016 KB |
Output is correct |
2 |
Correct |
2 ms |
8016 KB |
Output is correct |
3 |
Correct |
4 ms |
8548 KB |
Output is correct |
4 |
Correct |
4 ms |
8528 KB |
Output is correct |
5 |
Correct |
4 ms |
8696 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
5 ms |
8528 KB |
Output is correct |
8 |
Correct |
5 ms |
8528 KB |
Output is correct |
9 |
Correct |
4 ms |
8528 KB |
Output is correct |
10 |
Correct |
4 ms |
8528 KB |
Output is correct |
11 |
Correct |
316 ms |
44576 KB |
Output is correct |
12 |
Correct |
344 ms |
46588 KB |
Output is correct |
13 |
Correct |
355 ms |
49632 KB |
Output is correct |
14 |
Correct |
435 ms |
52552 KB |
Output is correct |
15 |
Correct |
451 ms |
52988 KB |
Output is correct |
16 |
Correct |
468 ms |
51964 KB |
Output is correct |
17 |
Correct |
392 ms |
54276 KB |
Output is correct |
18 |
Correct |
430 ms |
51964 KB |
Output is correct |
19 |
Correct |
393 ms |
55804 KB |
Output is correct |
20 |
Correct |
353 ms |
48380 KB |
Output is correct |
21 |
Correct |
291 ms |
46588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
8016 KB |
Output is correct |
2 |
Correct |
2 ms |
8016 KB |
Output is correct |
3 |
Correct |
4 ms |
8548 KB |
Output is correct |
4 |
Correct |
4 ms |
8528 KB |
Output is correct |
5 |
Correct |
4 ms |
8696 KB |
Output is correct |
6 |
Correct |
4 ms |
8272 KB |
Output is correct |
7 |
Correct |
5 ms |
8528 KB |
Output is correct |
8 |
Correct |
5 ms |
8528 KB |
Output is correct |
9 |
Correct |
4 ms |
8528 KB |
Output is correct |
10 |
Correct |
4 ms |
8528 KB |
Output is correct |
11 |
Correct |
316 ms |
44576 KB |
Output is correct |
12 |
Correct |
344 ms |
46588 KB |
Output is correct |
13 |
Correct |
355 ms |
49632 KB |
Output is correct |
14 |
Correct |
435 ms |
52552 KB |
Output is correct |
15 |
Correct |
451 ms |
52988 KB |
Output is correct |
16 |
Correct |
468 ms |
51964 KB |
Output is correct |
17 |
Correct |
392 ms |
54276 KB |
Output is correct |
18 |
Correct |
430 ms |
51964 KB |
Output is correct |
19 |
Correct |
393 ms |
55804 KB |
Output is correct |
20 |
Correct |
353 ms |
48380 KB |
Output is correct |
21 |
Correct |
291 ms |
46588 KB |
Output is correct |
22 |
Correct |
466 ms |
55304 KB |
Output is correct |
23 |
Correct |
437 ms |
52992 KB |
Output is correct |
24 |
Correct |
501 ms |
53164 KB |
Output is correct |
25 |
Correct |
491 ms |
59388 KB |
Output is correct |
26 |
Correct |
455 ms |
54864 KB |
Output is correct |
27 |
Correct |
522 ms |
53248 KB |
Output is correct |
28 |
Correct |
109 ms |
15612 KB |
Output is correct |
29 |
Correct |
371 ms |
48752 KB |
Output is correct |
30 |
Correct |
379 ms |
48748 KB |
Output is correct |
31 |
Correct |
393 ms |
49464 KB |
Output is correct |
32 |
Correct |
350 ms |
47256 KB |
Output is correct |