//Autor: Bartłomiej Czarkowski
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
template<class A,class B>auto&operator<<(ostream&o,pair<A,B>p){return o<<'('<<p.first<<", "<<p.second<<')';}
template<class T>auto operator<<(ostream&o,T x)->decltype(x.end(),o){o<<'{';int i=0;for(auto e:x)o<<(", ")+2*!i++<<e;return o<<'}';}
#define debug(x...) cerr<<"["#x"]: ",[](auto...$){((cerr<<$<<"; "),...);}(x),cerr<<'\n'
#else
#define debug(...) {}
#endif
struct edge {
int a, b;
};
const int N = 1001000;
int n, m, q, a, b, l;
vector<int> dp, sss, odw, gle, odp, stp, pd;
vector<edge> kr;
vector<vector<int>> v;
vector<vector<pair<int, int>>> vv;
void dfs_gle(int x) {
odw[x] = l;
for (int i : v[x]) {
if (odw[i] < l) {
gle[i] = gle[x] + 1;
dfs_gle(i);
}
}
}
void dfs_dp(int x) {
odw[x] = l;
for (int i : v[x]) {
if (odw[i] < l) {
dfs_dp(i);
dp[x] += dp[i];
}
}
}
void dfs_sss(int x) {
odw[x] = l;
for (int i : v[x]) {
if (odw[i] < l) {
if (dp[i] > 1) {
sss[i] = sss[x];
}
dfs_sss(i);
}
}
}
void get(int &a) {
a = 0;
int g = getchar_unlocked();
while (g < '0' || '9' < g) {
g = getchar_unlocked();
}
while ('0' <= g && g <= '9') {
a = (a << 3) + (a << 1) + g - '0';
g = getchar_unlocked();
}
}
int main() {
get(n);
get(m);
dp.resize(n + 1);
sss.resize(n + 1);
odw.resize(n + 1);
gle.resize(n + 1);
odp.resize(m + 1);
stp.resize(n + 1);
pd.resize(n + 1);
kr.resize(m + 1);
v.resize(n + 1);
vv.resize(n + 1);
for (int i = 1; i <= m; ++i) {
get(a);
get(b);
v[a].push_back(b);
v[b].push_back(a);
kr[i].a = a;
kr[i].b = b;
}
++l;
for (int i = 1; i <= n; ++i) {
if (odw[i] < l) {
dfs_gle(i);
}
}
for (int i = 1; i <= m; ++i) {
if (gle[kr[i].a] > gle[kr[i].b]) {
odp[i] = 1;
swap(kr[i].a, kr[i].b);
}
++dp[kr[i].b];
--dp[kr[i].a];
}
++l;
for (int i = 1; i <= n; ++i) {
if (odw[i] < l) {
dfs_dp(i);
}
sss[i] = i;
}
++l;
for (int i = 1; i <= n; ++i) {
if (odw[i] < l) {
dfs_sss(i);
}
}
for (int i = 1; i <= m; ++i) {
if (sss[kr[i].a] == sss[kr[i].b]) {
odp[i] = 2;
}
else {
vv[sss[kr[i].a]].push_back({sss[kr[i].b], i});
vv[sss[kr[i].b]].push_back({sss[kr[i].a], i});
++stp[sss[kr[i].a]];
++stp[sss[kr[i].b]];
}
}
get(q);
for (int i = 1; i <= q; ++i) {
get(a);
get(b);
++pd[sss[a]];
--pd[sss[b]];
}
queue<int> que;
for (int i = 1; i <= n; ++i) {
if (stp[i] == 1) {
que.push(i);
}
}
++l;
while (!que.empty()) {
int x = que.front();
que.pop();
odw[x] = l;
for (auto i : vv[x]) {
if (odw[i.first] < l) {
--stp[i.first];
if (pd[x] == 0) {
odp[i.second] = 2;
}
else if ((pd[x] > 0) == (x == kr[i.second].b)) {
odp[i.second] ^= 1;
}
pd[i.first] += pd[x];
if (stp[i.first] == 1) {
que.push(i.first);
}
}
}
}
for (int i = 1; i <= m; ++i) {
if (odp[i] == 0) {
printf("R");
}
else if (odp[i] == 1) {
printf("L");
}
else {
printf("B");
}
}
printf("\n");
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
24 ms |
6092 KB |
Output is correct |
12 |
Correct |
28 ms |
7556 KB |
Output is correct |
13 |
Correct |
34 ms |
9780 KB |
Output is correct |
14 |
Correct |
46 ms |
13004 KB |
Output is correct |
15 |
Correct |
52 ms |
14148 KB |
Output is correct |
16 |
Correct |
86 ms |
16872 KB |
Output is correct |
17 |
Correct |
77 ms |
17676 KB |
Output is correct |
18 |
Correct |
79 ms |
16888 KB |
Output is correct |
19 |
Correct |
70 ms |
18252 KB |
Output is correct |
20 |
Correct |
31 ms |
8796 KB |
Output is correct |
21 |
Correct |
28 ms |
8764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
304 KB |
Output is correct |
4 |
Correct |
1 ms |
436 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
440 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
24 ms |
6092 KB |
Output is correct |
12 |
Correct |
28 ms |
7556 KB |
Output is correct |
13 |
Correct |
34 ms |
9780 KB |
Output is correct |
14 |
Correct |
46 ms |
13004 KB |
Output is correct |
15 |
Correct |
52 ms |
14148 KB |
Output is correct |
16 |
Correct |
86 ms |
16872 KB |
Output is correct |
17 |
Correct |
77 ms |
17676 KB |
Output is correct |
18 |
Correct |
79 ms |
16888 KB |
Output is correct |
19 |
Correct |
70 ms |
18252 KB |
Output is correct |
20 |
Correct |
31 ms |
8796 KB |
Output is correct |
21 |
Correct |
28 ms |
8764 KB |
Output is correct |
22 |
Correct |
75 ms |
18660 KB |
Output is correct |
23 |
Correct |
88 ms |
17800 KB |
Output is correct |
24 |
Correct |
85 ms |
18080 KB |
Output is correct |
25 |
Correct |
71 ms |
20476 KB |
Output is correct |
26 |
Correct |
73 ms |
18480 KB |
Output is correct |
27 |
Correct |
78 ms |
17852 KB |
Output is correct |
28 |
Correct |
13 ms |
3796 KB |
Output is correct |
29 |
Correct |
37 ms |
9676 KB |
Output is correct |
30 |
Correct |
35 ms |
9788 KB |
Output is correct |
31 |
Correct |
38 ms |
9980 KB |
Output is correct |
32 |
Correct |
45 ms |
13208 KB |
Output is correct |