#include <bits/stdc++.h>
using namespace std;
#define rep(i , j , k) for(int i = j; i < k; i++)
#define pb push_back
typedef long long ll;
typedef pair<int , int> pii;
typedef vector<int> vi;
template<typename S, typename T>
inline bool smin(S &l, T r) { return l < r ? 0 : (l = r, 1); }
template<typename S, typename T>
inline bool smax(S &l, T r) { return r < l ? 0 : (l = r, 1); }
constexpr int N = 1e5 + 10;
int n, m, p, a[N], b[N], COLOR, val[N];
vi adj[N], adj2[N];
int h[N], dp[N], inp[N], col[N];
bitset<N> mark;
void dfs2(int v, int cl, int id = -1) {
mark[v] = true;
if (col[v] != cl && col[v]) {
adj2[cl].pb(inp[v]);
cl = col[v];
}
col[v] = cl;
for (auto e : adj[v]) {
int u = a[e] ^ b[e] ^ v;
if (!mark[u])
dfs2(u , cl , e);
}
}
void dfs(int v, int id = m) {
mark[v] = true;
dp[v] = h[v];
for (auto e : adj[v]) {
if (e == id) continue;
int u = a[e] ^ b[e] ^ v;
if (mark[u])
smin(dp[v] , h[u]);
else {
h[u] = h[v] + 1;
dfs(u, e);
smin(dp[v] , dp[u]);
}
}
if (dp[v] == h[v]) {
col[v] = ++COLOR;
inp[v] = id;
}
}
char res[N];
void dfs3(int v, int id = m) {
for (auto e : adj2[v]) {
int u = v ^ col[a[e]] ^ col[b[e]];
dfs3(u, e);
val[v] += val[u];
}
if (val[v] == 0) return;
res[id] = (val[v] < 0) == (col[b[id]] == v) ? 'R' : 'L';
}
int main() {
ios::sync_with_stdio(0);
cin >> n >> m;
rep(i , 0 , m) {
cin >> a[i] >> b[i];
adj[a[i]].pb(i);
adj[b[i]].pb(i);
}
vector<pii> ziba;
rep(i , 1 , n + 1)
if (!mark[i]) {
dfs(i);
ziba.pb({i , COLOR});
}
mark.reset();
for (auto e : ziba)
dfs2(e.first , e.second);
cin >> p;
rep(i , 0 , p) {
int u , v;
cin >> u >> v;
u = col[u] , v = col[v];
val[u]++;
val[v]--;
}
memset(res , 'B', sizeof(res));
for (auto e : ziba)
dfs3(e.second);
rep(i , 0 , m)
cout << res[i];
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
5248 KB |
Output is correct |
4 |
Correct |
7 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5376 KB |
Output is correct |
6 |
Correct |
8 ms |
5248 KB |
Output is correct |
7 |
Correct |
9 ms |
5248 KB |
Output is correct |
8 |
Correct |
7 ms |
5248 KB |
Output is correct |
9 |
Correct |
6 ms |
5248 KB |
Output is correct |
10 |
Correct |
8 ms |
5248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
5248 KB |
Output is correct |
4 |
Correct |
7 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5376 KB |
Output is correct |
6 |
Correct |
8 ms |
5248 KB |
Output is correct |
7 |
Correct |
9 ms |
5248 KB |
Output is correct |
8 |
Correct |
7 ms |
5248 KB |
Output is correct |
9 |
Correct |
6 ms |
5248 KB |
Output is correct |
10 |
Correct |
8 ms |
5248 KB |
Output is correct |
11 |
Correct |
81 ms |
10208 KB |
Output is correct |
12 |
Correct |
110 ms |
11296 KB |
Output is correct |
13 |
Correct |
108 ms |
12496 KB |
Output is correct |
14 |
Correct |
126 ms |
13684 KB |
Output is correct |
15 |
Correct |
141 ms |
14108 KB |
Output is correct |
16 |
Correct |
153 ms |
14072 KB |
Output is correct |
17 |
Correct |
151 ms |
16120 KB |
Output is correct |
18 |
Correct |
187 ms |
14044 KB |
Output is correct |
19 |
Correct |
132 ms |
17400 KB |
Output is correct |
20 |
Correct |
116 ms |
11140 KB |
Output is correct |
21 |
Correct |
69 ms |
11000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
5120 KB |
Output is correct |
2 |
Correct |
8 ms |
5120 KB |
Output is correct |
3 |
Correct |
8 ms |
5248 KB |
Output is correct |
4 |
Correct |
7 ms |
5248 KB |
Output is correct |
5 |
Correct |
8 ms |
5376 KB |
Output is correct |
6 |
Correct |
8 ms |
5248 KB |
Output is correct |
7 |
Correct |
9 ms |
5248 KB |
Output is correct |
8 |
Correct |
7 ms |
5248 KB |
Output is correct |
9 |
Correct |
6 ms |
5248 KB |
Output is correct |
10 |
Correct |
8 ms |
5248 KB |
Output is correct |
11 |
Correct |
81 ms |
10208 KB |
Output is correct |
12 |
Correct |
110 ms |
11296 KB |
Output is correct |
13 |
Correct |
108 ms |
12496 KB |
Output is correct |
14 |
Correct |
126 ms |
13684 KB |
Output is correct |
15 |
Correct |
141 ms |
14108 KB |
Output is correct |
16 |
Correct |
153 ms |
14072 KB |
Output is correct |
17 |
Correct |
151 ms |
16120 KB |
Output is correct |
18 |
Correct |
187 ms |
14044 KB |
Output is correct |
19 |
Correct |
132 ms |
17400 KB |
Output is correct |
20 |
Correct |
116 ms |
11140 KB |
Output is correct |
21 |
Correct |
69 ms |
11000 KB |
Output is correct |
22 |
Correct |
170 ms |
17264 KB |
Output is correct |
23 |
Correct |
175 ms |
15608 KB |
Output is correct |
24 |
Correct |
176 ms |
15096 KB |
Output is correct |
25 |
Correct |
139 ms |
20552 KB |
Output is correct |
26 |
Correct |
149 ms |
16860 KB |
Output is correct |
27 |
Correct |
139 ms |
15608 KB |
Output is correct |
28 |
Correct |
45 ms |
8312 KB |
Output is correct |
29 |
Correct |
110 ms |
11764 KB |
Output is correct |
30 |
Correct |
104 ms |
12044 KB |
Output is correct |
31 |
Correct |
120 ms |
12280 KB |
Output is correct |
32 |
Correct |
114 ms |
15520 KB |
Output is correct |