#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];
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) {
continue;
}
if(visited[v] == false) {
dfs(v, u);
}
else {
ans[i] = 'B';
if(L[i] == u) {
swap(L[i], R[i]);
}
qs1[L[i]]++;
qs1[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);
}
}
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |