This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5 + 5;
#define all(x) x.begin(), x.end();
#define sz(x) (int)x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int n, m, p, up_edge[MAXN], ponte[MAXN], val[MAXN];
int niv[MAXN], vis[MAXN];
int A[MAXN], B[MAXN], S[MAXN], E[MAXN];
vector<pii> edges[MAXN];
string ans;
int dfs(int x, int up_edge) {
vis[x] = 1;
int lower_back = n;
for(auto [viz, ind] : edges[x]) {
if(!vis[viz]) {
niv[viz] = niv[x] + 1;
lower_back = min(lower_back, dfs(viz, ind));
}
else if(ind != up_edge) lower_back = min(lower_back, niv[viz]);
}
if(lower_back >= niv[x]) ponte[x] = 1;
return lower_back;
}
int calc_ans(int x, int up_edge) {
vis[x] = 1;
int at_val = val[x];
for(auto [viz, ind] : edges[x]) {
if(!vis[viz])
at_val += calc_ans(viz, ind);
}
if(at_val > 0 and ponte[x]) {
if(A[up_edge] == x) ans[up_edge] = 'R';
else ans[up_edge] = 'L';
}
if(at_val < 0 and ponte[x]) {
if(A[up_edge] == x) ans[up_edge] = 'L';
else ans[up_edge] = 'R';
}
return at_val;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> m;
for(int i = 0; i < m; i++) {
cin >> A[i] >> B[i];
edges[A[i]].pb({B[i], i});
edges[B[i]].pb({A[i], i});
ans += 'B';
}
cin >> p;
for(int i = 1; i <= p; i++)
cin >> S[i] >> E[i], val[S[i]]++, val[E[i]]--;
for(int i = 1; i <= n; i++)
if(!vis[i]) dfs(i, -1), ponte[i] = 0;
memset(vis, 0, sizeof(vis));
for(int i = 1; i <= n; i++)
if(!vis[i]) calc_ans(i, 0);
cout << ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |