#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define mp make_pair
#define pb push_back
#define ld long double
#define ss(x) (int) x.size()
#define FOR(i, j, n) for(int i = j; i <= n; ++i)
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl;
#define ios cin.tie(0); ios_base::sync_with_stdio(0)
using namespace std;
const int nax = 1e5 + 111;
int n, m;
int a, b;
vector <pair<int, int>> v[nax];
int h[nax];
pair<int, int> ed[nax];
int id;
int nr[nax];
bool odw[nax];
int low[nax];
stack <int> stos;
void dfs(int u, int ind) {
stos.push(u);
low[u] = h[u];
odw[u] = 1;
for(auto it : v[u]) {
if(it.fi == ind)
continue;
if(!odw[it.se]) {
h[it.se] = h[u] + 1;
dfs(it.se, it.fi);
low[u] = min(low[u], low[it.se]);
}
else {
low[u] = min(low[u], h[it.se]);
}
}
if(low[u] == h[u]) {
id += 1;
while(!stos.empty() && stos.top() != u) {
nr[stos.top()] = id;
stos.pop();
}
nr[u] = id;
stos.pop();
}
}
vector <pair<int, int>> graf[nax];
pair<int, int> kraw[nax];
int q;
int sum[nax];
void solve(int u, int p = 0, int ind = -1) {
odw[u] = 1;
for(auto it : graf[u])
if(!odw[it.se]) {
solve(it.se, u, it.fi);
sum[u] += sum[it.se];
}
if(ind != -1 && sum[u] != 0) {
if(sum[u] > 0)
kraw[ind] = mp(u, p);
else
kraw[ind] = mp(p, u);
}
}
int main() {
scanf("%d%d", &n, &m);
FOR(i, 1, m) {
scanf("%d%d", &a, &b);
ed[i] = mp(a, b);
if(a == b) {
continue;
}
v[a].pb(mp(i, b));
v[b].pb(mp(i, a));
}
FOR(i, 1, n)
if(!odw[i])
dfs(i, -1);
FOR(i, 1, n)
for(auto it : v[i])
if(nr[i] != nr[it.se])
graf[nr[i]].pb(mp(it.fi, nr[it.se]));
scanf("%d", &q);
while(q--) {
scanf("%d%d", &a, &b);
if(nr[a] == nr[b])
continue;
sum[nr[a]] += 1;
sum[nr[b]] -= 1;
}
FOR(i, 1, id)
odw[i] = 0;
FOR(i, 1, id)
if(!odw[i])
solve(i);
FOR(i, 1, m) {
if(kraw[i] == mp(0, 0)) {
printf("B");
continue;
}
ed[i].fi = nr[ed[i].fi];
ed[i].se = nr[ed[i].se];
if(kraw[i] == ed[i])
printf("R");
else
printf("L");
}
return 0;
}
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:82:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
oneway.cpp:101:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
~~~~~^~~~~~~~~~
oneway.cpp:103:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &a, &b);
~~~~~^~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
5112 KB |
Output is correct |
4 |
Correct |
7 ms |
5112 KB |
Output is correct |
5 |
Correct |
7 ms |
5240 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
7 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5112 KB |
Output is correct |
10 |
Correct |
7 ms |
5112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
5112 KB |
Output is correct |
4 |
Correct |
7 ms |
5112 KB |
Output is correct |
5 |
Correct |
7 ms |
5240 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
7 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5112 KB |
Output is correct |
10 |
Correct |
7 ms |
5112 KB |
Output is correct |
11 |
Correct |
58 ms |
11028 KB |
Output is correct |
12 |
Correct |
66 ms |
11896 KB |
Output is correct |
13 |
Correct |
71 ms |
13048 KB |
Output is correct |
14 |
Correct |
89 ms |
14328 KB |
Output is correct |
15 |
Correct |
108 ms |
14832 KB |
Output is correct |
16 |
Correct |
112 ms |
16376 KB |
Output is correct |
17 |
Correct |
111 ms |
18168 KB |
Output is correct |
18 |
Correct |
116 ms |
16880 KB |
Output is correct |
19 |
Correct |
112 ms |
19804 KB |
Output is correct |
20 |
Correct |
68 ms |
11640 KB |
Output is correct |
21 |
Correct |
62 ms |
12152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4984 KB |
Output is correct |
2 |
Correct |
6 ms |
4984 KB |
Output is correct |
3 |
Correct |
7 ms |
5112 KB |
Output is correct |
4 |
Correct |
7 ms |
5112 KB |
Output is correct |
5 |
Correct |
7 ms |
5240 KB |
Output is correct |
6 |
Correct |
6 ms |
5112 KB |
Output is correct |
7 |
Correct |
7 ms |
5112 KB |
Output is correct |
8 |
Correct |
7 ms |
5112 KB |
Output is correct |
9 |
Correct |
7 ms |
5112 KB |
Output is correct |
10 |
Correct |
7 ms |
5112 KB |
Output is correct |
11 |
Correct |
58 ms |
11028 KB |
Output is correct |
12 |
Correct |
66 ms |
11896 KB |
Output is correct |
13 |
Correct |
71 ms |
13048 KB |
Output is correct |
14 |
Correct |
89 ms |
14328 KB |
Output is correct |
15 |
Correct |
108 ms |
14832 KB |
Output is correct |
16 |
Correct |
112 ms |
16376 KB |
Output is correct |
17 |
Correct |
111 ms |
18168 KB |
Output is correct |
18 |
Correct |
116 ms |
16880 KB |
Output is correct |
19 |
Correct |
112 ms |
19804 KB |
Output is correct |
20 |
Correct |
68 ms |
11640 KB |
Output is correct |
21 |
Correct |
62 ms |
12152 KB |
Output is correct |
22 |
Correct |
176 ms |
19252 KB |
Output is correct |
23 |
Correct |
139 ms |
17912 KB |
Output is correct |
24 |
Correct |
136 ms |
18188 KB |
Output is correct |
25 |
Correct |
163 ms |
22904 KB |
Output is correct |
26 |
Correct |
137 ms |
19316 KB |
Output is correct |
27 |
Correct |
133 ms |
18040 KB |
Output is correct |
28 |
Correct |
51 ms |
9080 KB |
Output is correct |
29 |
Correct |
92 ms |
12408 KB |
Output is correct |
30 |
Correct |
92 ms |
12844 KB |
Output is correct |
31 |
Correct |
90 ms |
12920 KB |
Output is correct |
32 |
Correct |
103 ms |
15996 KB |
Output is correct |