#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
const int MAX_M = 1e5 + 5;
vector <int> graph[MAX_N];
int L[MAX_M], R[MAX_M];
bool visited[MAX_N];
bool incycle[MAX_M];
int qs1[MAX_N], qs2[MAX_N];
char ans[MAX_M];
void dfs(int u, int p) {
visited[u] = true;
for(auto i : graph[u]) {
int v = u ^ L[i] ^ R[i];
if(v == p or incycle[i] == true) {
continue;
}
if(visited[v] == false) {
dfs(v, u);
}
else {
incycle[i] = true;
if(L[i] == v) {
swap(L[i], R[i]);
}
}
}
}
void dfs2(int u, int p) {
visited[u] = false;
for(auto i : graph[u]) {
int v = u ^ L[i] ^ R[i];
if(v != p and visited[v] == true) {
dfs2(v, u);
ans[i] = 'B';
qs1[u] += qs1[v];
qs2[u] += qs2[v];
if(qs1[v] != 0 or qs2[v] == 0) {
continue;
}
if(qs2[v] > 0) {
if(v == L[i]) {
ans[i] = 'R';
}
else {
ans[i] = 'L';
}
}
else {
if(u == L[i]) {
ans[i] = 'R';
}
else {
ans[i] = 'L';
}
}
}
}
}
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int n, m;
cin >> n >> m;
for(int i = 1; i <= m; i++) {
cin >> L[i] >> R[i];
graph[L[i]].push_back(i);
graph[R[i]].push_back(i);
}
for(int i = 1; i <= n; i++) {
if(visited[i] == false) {
dfs(i, -1);
}
}
for(int i = 1; i <= m; i++) {
if(incycle[i] == true) {
ans[i] = 'B';
qs1[L[i]]++;
qs1[R[i]]--;
}
}
int p;
cin >> p;
for(int i = 1; i <= p; i++) {
int x, y;
cin >> x >> y;
qs2[x]++;
qs2[y]--;
}
for(int i = 1; i <= n; i++) {
if(visited[i] == true) {
dfs2(i, -1);
}
}
for(int i = 1; i <= m; i++) {
cout << ans[i];
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
2 ms |
2644 KB |
Output is correct |
4 |
Correct |
2 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2772 KB |
Output is correct |
6 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |