#include <bits/stdc++.h>
using namespace std;
struct Edge
{
unsigned v, i;
bool as_given;
Edge(unsigned v_, unsigned i_, bool as_given_)
{
v = v_, i = i_, as_given = as_given_;
}
};
vector<vector<Edge>> g;
vector<int> r;
vector<unsigned> y, l;
vector<bool> visited;
string orientation;
unsigned orient_edges(unsigned u, Edge p = Edge(-1, -1, 0), unsigned i = 0)
{
visited[u] = 1;
y[u] = l[u] = i++;
for (Edge const &e : g[u])
{
if (!visited[e.v])
{
i = orient_edges(e.v, e, i);
r[u] += r[e.v];
l[u] = min(l[u], l[e.v]);
}
if (e.i != p.i)
{
if (l[e.v] > y[u] && r[e.v])
orientation[e.i] = ((r[e.v] > 0) ^ !e.as_given) ? 'L' : 'R';
else
orientation[e.i] = 'B';
l[u] = min(l[u], y[e.v]);
}
}
return i;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
size_t n, m;
cin >> n >> m;
g = vector<vector<Edge>>(n);
r = vector<int>(n, 0);
y = vector<unsigned>(n);
l = vector<unsigned>(n);
visited = vector<bool>(n, 0);
orientation.resize(m);
for (unsigned i = 0; i < m; i++)
{
unsigned u, v;
cin >> u >> v;
g[u - 1].emplace_back(v - 1, i, 1);
g[v - 1].emplace_back(u - 1, i, 0);
}
size_t p;
cin >> p;
for (size_t i = 0; i < p; i++)
{
unsigned u, v;
cin >> u >> v;
r[u - 1]++;
r[v - 1]--;
}
for (unsigned i = 0; i < n; i++)
if (!visited[i])
orient_edges(i);
cout << orientation << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
272 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
272 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
35 ms |
7024 KB |
Output is correct |
12 |
Correct |
33 ms |
8136 KB |
Output is correct |
13 |
Correct |
38 ms |
9284 KB |
Output is correct |
14 |
Correct |
45 ms |
10444 KB |
Output is correct |
15 |
Correct |
46 ms |
10708 KB |
Output is correct |
16 |
Correct |
48 ms |
9508 KB |
Output is correct |
17 |
Correct |
38 ms |
10412 KB |
Output is correct |
18 |
Correct |
40 ms |
9324 KB |
Output is correct |
19 |
Correct |
40 ms |
11392 KB |
Output is correct |
20 |
Correct |
33 ms |
8012 KB |
Output is correct |
21 |
Correct |
30 ms |
7748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
272 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
320 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
320 KB |
Output is correct |
11 |
Correct |
35 ms |
7024 KB |
Output is correct |
12 |
Correct |
33 ms |
8136 KB |
Output is correct |
13 |
Correct |
38 ms |
9284 KB |
Output is correct |
14 |
Correct |
45 ms |
10444 KB |
Output is correct |
15 |
Correct |
46 ms |
10708 KB |
Output is correct |
16 |
Correct |
48 ms |
9508 KB |
Output is correct |
17 |
Correct |
38 ms |
10412 KB |
Output is correct |
18 |
Correct |
40 ms |
9324 KB |
Output is correct |
19 |
Correct |
40 ms |
11392 KB |
Output is correct |
20 |
Correct |
33 ms |
8012 KB |
Output is correct |
21 |
Correct |
30 ms |
7748 KB |
Output is correct |
22 |
Correct |
54 ms |
11596 KB |
Output is correct |
23 |
Correct |
56 ms |
10432 KB |
Output is correct |
24 |
Correct |
68 ms |
10556 KB |
Output is correct |
25 |
Correct |
56 ms |
14032 KB |
Output is correct |
26 |
Correct |
50 ms |
11332 KB |
Output is correct |
27 |
Correct |
51 ms |
10408 KB |
Output is correct |
28 |
Correct |
23 ms |
4692 KB |
Output is correct |
29 |
Correct |
53 ms |
8836 KB |
Output is correct |
30 |
Correct |
48 ms |
8840 KB |
Output is correct |
31 |
Correct |
48 ms |
9224 KB |
Output is correct |
32 |
Correct |
45 ms |
10884 KB |
Output is correct |