#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5;
vector<int> adj[MAXN+1];
map<pair<int,int>, int> edge, dir;
map<pair<int,int>, char> ans;
int dep[MAXN+1], low[MAXN+1], cntX[MAXN+1], cntY[MAXN+1];
void dfs(int v, int p) {
dep[v] = low[v] = dep[p] + 1;
for (int u : adj[v]) {
if (u == p) continue;
if (dep[u] == 0) {
dfs(u, v);
low[v] = min(low[v], low[u]);
cntX[v] += cntX[u];
cntY[v] += cntY[u];
} else {
low[v] = min(low[v], dep[u]);
}
}
int node1 = v, node2 = p;
if (cntX[v] == cntY[v] || dep[v] != low[v] || edge[{node1, node2}] != 1) return;
if (!dir[{node1, node2}]) swap(node1, node2);
pair<int,int> orient;
if (cntX[v] > cntY[v]) {
// edge should go from v -> p
orient = {v, p};
} else {
orient = {p, v};
}
if (orient == make_pair(node1, node2)) {
ans[{node1, node2}] = 'R';
} else {
ans[{node1, node2}] = 'L';
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n,m; cin >> n >> m;
pair<int,int> graph[m];
for (int i = 0; i < m; i++) {
int a,b; cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
edge[{a, b}]++;
edge[{b, a}]++;
dir[{a, b}] = 1;
graph[i] = {a, b};
}
int p; cin >> p;
while (p--) {
int x,y; cin >> x >> y;
cntX[x]++, cntY[y]++;
}
for (int v = 1; v <= n; v++) {
if (dep[v] == 0) {
dfs(v,0);
}
}
for (auto [a,b] : graph) {
cout << (!ans.count({a,b}) ? 'B' : ans[{a,b}]);
}
}
Compilation message
oneway.cpp: In function 'int main()':
oneway.cpp:70:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
70 | for (auto [a,b] : graph) {
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4012 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
3 ms |
4472 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
3 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
4188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4012 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
3 ms |
4472 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
3 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
4188 KB |
Output is correct |
11 |
Correct |
135 ms |
28500 KB |
Output is correct |
12 |
Correct |
160 ms |
29780 KB |
Output is correct |
13 |
Correct |
157 ms |
30804 KB |
Output is correct |
14 |
Correct |
189 ms |
31316 KB |
Output is correct |
15 |
Correct |
199 ms |
31144 KB |
Output is correct |
16 |
Correct |
168 ms |
28244 KB |
Output is correct |
17 |
Correct |
199 ms |
34644 KB |
Output is correct |
18 |
Correct |
180 ms |
28496 KB |
Output is correct |
19 |
Correct |
206 ms |
36600 KB |
Output is correct |
20 |
Correct |
144 ms |
29104 KB |
Output is correct |
21 |
Correct |
117 ms |
27988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4188 KB |
Output is correct |
2 |
Correct |
1 ms |
4012 KB |
Output is correct |
3 |
Correct |
2 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 KB |
Output is correct |
5 |
Correct |
2 ms |
4440 KB |
Output is correct |
6 |
Correct |
2 ms |
4184 KB |
Output is correct |
7 |
Correct |
3 ms |
4472 KB |
Output is correct |
8 |
Correct |
2 ms |
4444 KB |
Output is correct |
9 |
Correct |
3 ms |
4188 KB |
Output is correct |
10 |
Correct |
2 ms |
4188 KB |
Output is correct |
11 |
Correct |
135 ms |
28500 KB |
Output is correct |
12 |
Correct |
160 ms |
29780 KB |
Output is correct |
13 |
Correct |
157 ms |
30804 KB |
Output is correct |
14 |
Correct |
189 ms |
31316 KB |
Output is correct |
15 |
Correct |
199 ms |
31144 KB |
Output is correct |
16 |
Correct |
168 ms |
28244 KB |
Output is correct |
17 |
Correct |
199 ms |
34644 KB |
Output is correct |
18 |
Correct |
180 ms |
28496 KB |
Output is correct |
19 |
Correct |
206 ms |
36600 KB |
Output is correct |
20 |
Correct |
144 ms |
29104 KB |
Output is correct |
21 |
Correct |
117 ms |
27988 KB |
Output is correct |
22 |
Correct |
359 ms |
41144 KB |
Output is correct |
23 |
Correct |
286 ms |
38480 KB |
Output is correct |
24 |
Correct |
342 ms |
38292 KB |
Output is correct |
25 |
Correct |
289 ms |
45892 KB |
Output is correct |
26 |
Correct |
342 ms |
40276 KB |
Output is correct |
27 |
Correct |
307 ms |
38228 KB |
Output is correct |
28 |
Correct |
59 ms |
8532 KB |
Output is correct |
29 |
Correct |
166 ms |
29524 KB |
Output is correct |
30 |
Correct |
133 ms |
29620 KB |
Output is correct |
31 |
Correct |
155 ms |
30292 KB |
Output is correct |
32 |
Correct |
165 ms |
31968 KB |
Output is correct |