#include <bits/stdc++.h>
using namespace std;
const int mxN = 1e5+2;
map<int, int> eidx[mxN];
vector<int> g[mxN], dfsg[mxN], upe[mxN], doe[mxN];
int dep[mxN], dp[mxN], parent[mxN], isbridge[mxN];
bool visited[mxN];
void dfsinit(int s, int e) {
visited[s] = 1;
for (auto u : g[s]) {
if (visited[u]) {
if (u == e) continue;
if (dep[u] < dep[s]) {
upe[s].push_back(u);
}
else {
doe[s].push_back(u);
}
continue;
}
dfsg[s].push_back(u);
dep[u] = dep[s] + 1, parent[u] = s;
dfsinit(u, s);
dp[s] += dp[u];
}
}
void dfsbridge(int s, int e) {
isbridge[s] = upe[s].size() - doe[s].size();
for (auto u : dfsg[s]) {
dfsbridge(u, s);
isbridge[s] += isbridge[u];
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, m, p;
cin >> n >> m;
vector<char> ans(m, 'B');
pair<int, int> e[m];
for (int i = 0; i < m; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
e[i] = {u, v};
if (u == v) continue;
eidx[u][v] = eidx[v][u] = i;
g[u].push_back(v), g[v].push_back(u);
}
cin >> p;
while (p--) {
int u, v;
cin >> u >> v;
u--, v--;
dp[u]++, dp[v]--;
}
for (int i = 0; i < n; ++i) {
if (!visited[i]) {
parent[i] = i;
dfsinit(i, -1);
dfsbridge(i, -1);
}
}
for (int i = 0; i < n; ++i) {
if (isbridge[i] == 0 && parent[i] != i && dp[i] != 0) {
ans[eidx[i][parent[i]]] = ((e[eidx[i][parent[i]]].first == i) ^ (dp[i] < 0) ? 'R' : 'L');
}
}
for (auto c : ans) cout << c;
cout << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
5 ms |
15964 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
5 ms |
15964 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
15960 KB |
Output is correct |
2 |
Incorrect |
5 ms |
15964 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |