//! The Leader Of Retards Bemola
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef pair<ll, ll> pll;
#define sz(x) (ll) x.size()
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
ll Pow(ll a, ll b, ll md, ll ans = 1) {
for (; b; b >>= 1, a = a * a % md)
if (b & 1)
ans = ans * a % md;
return ans % md;
}
const ll MAXN = 1e5 + 10;
const ll LOG = 18;
const ll MOD = 1e9 + 7;
ll A[MAXN], B[MAXN], P[MAXN], M[MAXN], L[MAXN], ps[MAXN], mark[MAXN], n, m, k, timer;
vector<pll> adj[MAXN]; pll E[MAXN];
void preDFS(ll v, ll p = -1) {
mark[v] = 1;
M[v] = L[v] = ++timer;
for (pll u : adj[v]) {
if (u.S == p) continue;
if (L[u.F] != 0) {
M[v] = min(M[v], L[u.F]);
} else {
preDFS(u.F, u.S);
if (M[u.F] > L[v]) B[u.S] = 1;
M[v] = min(M[v], M[u.F]);
}
}
}
ll Find(ll v) { return P[v] == -1 ? v : P[v] = Find(P[v]); }
void Union(ll u, ll v) {
u = Find(u), v = Find(v);
return (u == v ? void() : void(P[u] = v));
}
void DFS(ll v, ll p = -1) {
mark[v] = 1;
for (pll u : adj[v]) {
if (u.F == p) continue;
DFS(u.F, v);
if (ps[u.F] < 0) {
if (Find(E[u.S].F) == v) A[u.S] = 1;
else A[u.S] = -1;
} else if (ps[u.F] > 0) {
if (Find(E[u.S].F) == v) A[u.S] = -1;
else A[u.S] = 1;
}
ps[v] += ps[u.F];
}
}
int main() {
fill(P, P + MAXN, -1);
scanf("%d%d", &n, &m);
for (ll i = 1; i <= m; i++) {
ll u, v; scanf("%d%d", &u, &v);
adj[v].push_back({u, i});
adj[u].push_back({v, i}); E[i] = {u, v};
}
for (ll i = 1; i <= n; i++) if (mark[i] == 0) preDFS(i);
for (ll i = 1; i <= m; i++) {
if (B[i] == 0) Union(E[i].F, E[i].S);
}
for (ll i = 1; i <= n; i++) adj[i].clear(), adj[i].shrink_to_fit();
for (ll i = 1; i <= m; i++) {
if (B[i]) {
ll u = Find(E[i].F), v = Find(E[i].S);
adj[u].push_back({v, i});
adj[v].push_back({u, i});
}
}
scanf("%d", &k);
for (ll i = 1; i <= k; i++) {
ll u, v; scanf("%d%d", &u, &v);
u = Find(u), v = Find(v);
ps[u]++, ps[v]--;
}
fill(mark, mark + MAXN, 0);
for (ll i = 1; i <= n; i++) {
if (mark[Find(i)] == 0) DFS(Find(i));
}
for (ll i = 1; i <= m; i++) {
if (A[i] == 1) printf("R");
else if (A[i] == -1) printf("L");
else printf("B");
}
printf("\n");
return 0;
}
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:68:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
68 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:70:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
70 | ll u, v; scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:86:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
86 | scanf("%d", &k);
| ~~~~~^~~~~~~~~~
oneway.cpp:88:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
88 | ll u, v; scanf("%d%d", &u, &v);
| ~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3564 KB |
Output is correct |
4 |
Correct |
3 ms |
3564 KB |
Output is correct |
5 |
Correct |
4 ms |
3564 KB |
Output is correct |
6 |
Correct |
3 ms |
3564 KB |
Output is correct |
7 |
Correct |
3 ms |
3564 KB |
Output is correct |
8 |
Correct |
3 ms |
3564 KB |
Output is correct |
9 |
Correct |
3 ms |
3564 KB |
Output is correct |
10 |
Correct |
3 ms |
3564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3564 KB |
Output is correct |
4 |
Correct |
3 ms |
3564 KB |
Output is correct |
5 |
Correct |
4 ms |
3564 KB |
Output is correct |
6 |
Correct |
3 ms |
3564 KB |
Output is correct |
7 |
Correct |
3 ms |
3564 KB |
Output is correct |
8 |
Correct |
3 ms |
3564 KB |
Output is correct |
9 |
Correct |
3 ms |
3564 KB |
Output is correct |
10 |
Correct |
3 ms |
3564 KB |
Output is correct |
11 |
Correct |
57 ms |
9444 KB |
Output is correct |
12 |
Correct |
64 ms |
10724 KB |
Output is correct |
13 |
Correct |
91 ms |
12004 KB |
Output is correct |
14 |
Correct |
98 ms |
12772 KB |
Output is correct |
15 |
Correct |
98 ms |
13028 KB |
Output is correct |
16 |
Correct |
103 ms |
10852 KB |
Output is correct |
17 |
Correct |
114 ms |
13156 KB |
Output is correct |
18 |
Correct |
114 ms |
11108 KB |
Output is correct |
19 |
Correct |
97 ms |
14436 KB |
Output is correct |
20 |
Correct |
68 ms |
10232 KB |
Output is correct |
21 |
Correct |
59 ms |
10596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
3436 KB |
Output is correct |
2 |
Correct |
3 ms |
3436 KB |
Output is correct |
3 |
Correct |
3 ms |
3564 KB |
Output is correct |
4 |
Correct |
3 ms |
3564 KB |
Output is correct |
5 |
Correct |
4 ms |
3564 KB |
Output is correct |
6 |
Correct |
3 ms |
3564 KB |
Output is correct |
7 |
Correct |
3 ms |
3564 KB |
Output is correct |
8 |
Correct |
3 ms |
3564 KB |
Output is correct |
9 |
Correct |
3 ms |
3564 KB |
Output is correct |
10 |
Correct |
3 ms |
3564 KB |
Output is correct |
11 |
Correct |
57 ms |
9444 KB |
Output is correct |
12 |
Correct |
64 ms |
10724 KB |
Output is correct |
13 |
Correct |
91 ms |
12004 KB |
Output is correct |
14 |
Correct |
98 ms |
12772 KB |
Output is correct |
15 |
Correct |
98 ms |
13028 KB |
Output is correct |
16 |
Correct |
103 ms |
10852 KB |
Output is correct |
17 |
Correct |
114 ms |
13156 KB |
Output is correct |
18 |
Correct |
114 ms |
11108 KB |
Output is correct |
19 |
Correct |
97 ms |
14436 KB |
Output is correct |
20 |
Correct |
68 ms |
10232 KB |
Output is correct |
21 |
Correct |
59 ms |
10596 KB |
Output is correct |
22 |
Correct |
126 ms |
14180 KB |
Output is correct |
23 |
Correct |
126 ms |
12260 KB |
Output is correct |
24 |
Correct |
140 ms |
12404 KB |
Output is correct |
25 |
Correct |
123 ms |
17932 KB |
Output is correct |
26 |
Correct |
136 ms |
13796 KB |
Output is correct |
27 |
Correct |
116 ms |
12452 KB |
Output is correct |
28 |
Correct |
60 ms |
6756 KB |
Output is correct |
29 |
Correct |
105 ms |
10724 KB |
Output is correct |
30 |
Correct |
82 ms |
11364 KB |
Output is correct |
31 |
Correct |
95 ms |
11100 KB |
Output is correct |
32 |
Correct |
97 ms |
13924 KB |
Output is correct |