# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
303943 | peuch | One-Way Streets (CEOI17_oneway) | C++17 | 229 ms | 33272 KiB |
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;
const int MAXN = 100010;
int n, m, p;
int low[MAXN], pre[MAXN];
int cnt;
int bridge[MAXN];
pair<int, int> edge[MAXN];
int rep[MAXN], tam[MAXN];
int auxSum[MAXN];
int marc[MAXN];
int ans[MAXN];
vector<int> ar[MAXN], id[MAXN];
vector<int> tree[MAXN], treeID[MAXN];
void dfs(int cur, int pai);
void uni(int a, int b);
int find(int a);
void endCalc(int cur, int pai);
int main(){
scanf("%d %d", &n, &m);
for(int i = 1; i <= n; i++) rep[i] = i, tam[i] = 1;
for(int i = 1; i <= m; i++){
int a, b;
scanf("%d %d", &a, &b);
ar[a].push_back(b);
ar[b].push_back(a);
id[a].push_back(i);
id[b].push_back(i);
edge[i] = make_pair(a, b);
}
for(int i = 1; i <= n; i++)
if(marc[i] != 1) dfs(i, 0);
for(int i = 1; i <= m; i++){
if(bridge[i]) continue;
uni(edge[i].first, edge[i].second);
}
for(int i = 1; i <= m; i++){
if(!bridge[i]) continue;
int a = edge[i].first;
int b = edge[i].second;
a = find(a);
b = find(b);
tree[a].push_back(b);
tree[b].push_back(a);
treeID[a].push_back(i);
treeID[b].push_back(i);
}
scanf("%d", &p);
for(int i = 1; i <= p; i++){
int a, b;
scanf("%d %d", &a, &b);
a = find(a);
b = find(b);
auxSum[a]++;
auxSum[b]--;
}
for(int i = 1; i <= n; i++)
if(marc[find(i)] != 2) endCalc(find(i), 0);
for(int i = 1; i <= m; i++){
if(ans[i] == 1) printf("R");
else if(ans[i] == -1) printf("L");
else printf("B");
}
printf("\n");
return 0;
}
void dfs(int cur, int pai){
marc[cur] = 1;
pre[cur] = low[cur] = ++cnt;
for(int i = 0; i < ar[cur].size(); i++){
int viz = ar[cur][i];
if(id[cur][i] == pai) continue;
if(pre[viz] != 0) low[cur] = min(low[cur], pre[viz]);
else{
dfs(viz, id[cur][i]);
if(low[viz] > pre[cur]) bridge[id[cur][i]] = 1;
low[cur] = min(low[cur], low[viz]);
}
}
}
void uni(int a, int b){
a = find(a);
b = find(b);
if(a == b) return;
if(tam[a] > tam[b])
tam[a] += tam[b], rep[b] = a;
else
tam[b] += tam[a], rep[a] = b;
}
int find(int a){
if(rep[a] == a) return a;
return rep[a] = find(rep[a]);
}
void endCalc(int cur, int pai){
marc[cur] = 2;
for(int i = 0; i < tree[cur].size(); i++){
int viz = tree[cur][i];
int eID = treeID[cur][i];
if(viz == pai) continue;
endCalc(viz, cur);
if(auxSum[viz] < 0){
if(find(edge[eID].first) == cur) ans[eID] = 1;
else ans[eID] = -1;
}
else if(auxSum[viz] > 0){
if(find(edge[eID].first) == cur) ans[eID] = -1;
else ans[eID] = 1;
}
auxSum[cur] += auxSum[viz];
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |