#include <bits/stdc++.h>
using namespace std;
#define sz size
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
const int mxN = 1e5+5;
int vis[mxN];
vector<pii> adj[mxN];
int d[mxN];
int low[mxN];
char res[mxN];
int val[mxN];
void dfs(int c, int depth, int pidx){
d[c] = depth;
low[c] = depth;
for (pii i : adj[c]){
if (vis[abs(i.s)]) continue;
vis[abs(i.s)] = 1;
if (d[i.f] != -1){ low[c] = min(low[c],low[i.f]); res[abs(i.s)] = 'B'; continue;}
dfs(i.f,depth+1,i.s);
low[c] = min(low[c],low[i.f]);
val[c] += val[i.f];
}
//cout << c << " " << low[c] << " " << d[c] << "\n";
if (pidx == INT_MAX) return;
if (low[c] < d[c] || val[c] == 0) res[pidx] = 'B';
else if (val[c] < 0){
if (pidx > 0) res[abs(pidx)] = 'R';
else res[abs(pidx)] = 'L';
} else {
if (pidx > 0) res[abs(pidx)] = 'L';
else res[abs(pidx)] = 'R';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin >> n >> m;
int a,b;
for (int i =0; i < m; i++){
cin >> a >> b;
a -= 1;
b -= 1;
adj[a].pb((pii) {b,i+1});
adj[b].pb((pii) {a,-1*i-1});
}
int p;
cin >> p;
for (int i =0; i < p; i++){
cin >> a >> b;
a -= 1;
b -= 1;
val[a]++;
val[b]--;
}
memset(vis,0,sizeof(vis));
for (int i = 0; i < n; i++) d[i] = -1;
for (int i = 0; i < n; i++) if (d[i] == -1) dfs(i,0,INT_MAX);
for (int i = 1; i <= m; i++) cout << res[i];
cout << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
3072 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |