# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
211095 | mhy908 | One-Way Streets (CEOI17_oneway) | C++14 | 8 ms | 2816 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>
#define pb push_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
char ans[100010];
const LL hashnum=1000000ll;
unordered_map<LL, int> ump;
void inedge(int a, int b, int i){
ump[hashnum*a+b]=i;
ump[hashnum*b+a]=-i;
}
void getedge(int a, int b, char c){
int temp=ump[hashnum*a+b];
if(temp<0){
if(c=='L')c='R';
else c='L';
temp*=-1;
}
ans[temp]=c;
}
int n, m, p;
vector<int> link[100010];
int arr[100010], dfsnum[100010], re;
int solve(int num, int par){
dfsnum[num]=++re;
int ret=re;
for(int i:link[num]){
if(i==par)continue;
if(!dfsnum[i]){
int temp=solve(i, num);
if(temp>dfsnum[num]){
if(arr[i]<0)getedge(num, i, 'R');
if(arr[i]>0)getedge(num, i, 'L');
}
ret=min(ret, temp);
arr[num]+=arr[i];
}
else ret=min(ret, dfsnum[i]);
}
return ret;
}
int main(){
scanf("%d %d", &n, &m);
for(int i=1; i<=m; i++){
int a, b;
ans[i]='B';
scanf("%d %d", &a, &b);
inedge(a, b, i);
link[a].pb(b);
link[b].pb(a);
}
scanf("%d", &p);
for(int i=1; i<=p; i++){
int a, b;
scanf("%d %d", &a, &b);
arr[a]++, arr[b]--;
}
for(int i=1; i<=n; i++){
if(dfsnum[i])continue;
solve(i, 0);
}
for(int i=1; i<=m; i++)printf("%c", ans[i]);
}
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... |