Submission #159040

# Submission time Handle Problem Language Result Execution time Memory
159040 2019-10-20T08:53:43 Z brcode One-Way Streets (CEOI17_oneway) C++14
100 / 100
303 ms 26236 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
int currtime;
int n,m;
int k;
int a[MAXN];
vector<int> v1[MAXN];
int bg[MAXN];
vector<int> v2[MAXN];
int b[MAXN];
int p[MAXN];
int s[MAXN];
int tin[MAXN];
int dist[MAXN];
int low[MAXN];
int sz[MAXN];
int find(int a){
    if(p[a] == a){
        return a;
    }
    return p[a] = find(p[a]);
}
void join(int a,int b){
    a = find(a);
    b = find(b);
    if(a==b){
        return;
    }
    if(sz[a]<sz[b]){
        swap(a,b);
    }
    p[b] = a;
    sz[a] +=sz[b];
}
void dfs(int curr,int par){
    tin[curr] = low[curr] = currtime++;
    for(int x:v1[curr]){
        int next = curr^a[x]^b[x];
        if(!tin[next]){
            dfs(next,x);
            low[curr] = min(low[curr],low[next]);
            if(low[next]>tin[curr]){
                bg[x] = 1;
            }
        }else if(x!=par){
            low[curr]=min(low[curr],tin[next]);
        }
    }
}
void dfs2(int curr,int par){
    for(int x:v2[curr]){
        int next = curr^a[x]^b[x];
        if(next == par){
            continue;
        }
        dist[next] = dist[curr]+1;
        dfs2(next,curr);
        s[curr]+=s[next];
    }
}
int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        p[i] = i;
    }
    for(int i=1;i<=m;i++){
        cin>>a[i]>>b[i];
        v1[a[i]].push_back(i);
        v1[b[i]].push_back(i);
    }
    for(int i=1;i<=n;i++){
        if(!tin[i]){
            dfs(i,-1);
        }
    }
    for(int i=1;i<=m;i++){
        if(!bg[i]){
            join(a[i],b[i]);
        }
    }
    for(int i=1;i<=m;i++){
        if(!bg[i]){
            continue;
        }
        a[i]= find(a[i]);
        b[i] = find(b[i]);
        v2[a[i]].push_back(i);
        v2[b[i]].push_back(i);
    }
    cin>>k;
    while(k--){
        int x,y;
        cin>>x>>y;
        s[find(x)]++;
        s[find(y)]--;
    }
    for(int i=1;i<=n;i++){
        if(p[i] == i && !dist[i]){
            dist[i] = 1;
            dfs2(i,-1);
        }

    }
    for(int i=1;i<=m;i++){
        if(!bg[i]){
            cout<<'B';
            continue;
        }
        int node;
        if(dist[a[i]]>dist[b[i]]){
            node = a[i];
        }else{
            node = b[i];
        }
        if(s[node]==0){
            cout<<'B';
            continue;
        }
        if((s[node]>0 && node==a[i])||(s[node]<0 && node==b[i])){
            cout<<'R';
        }else{
            cout<<'L';
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9720 KB Output is correct
2 Correct 10 ms 9720 KB Output is correct
3 Correct 11 ms 9756 KB Output is correct
4 Correct 11 ms 9848 KB Output is correct
5 Correct 12 ms 9848 KB Output is correct
6 Correct 11 ms 9852 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 11 ms 9848 KB Output is correct
9 Correct 11 ms 9848 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9720 KB Output is correct
2 Correct 10 ms 9720 KB Output is correct
3 Correct 11 ms 9756 KB Output is correct
4 Correct 11 ms 9848 KB Output is correct
5 Correct 12 ms 9848 KB Output is correct
6 Correct 11 ms 9852 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 11 ms 9848 KB Output is correct
9 Correct 11 ms 9848 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 134 ms 14704 KB Output is correct
12 Correct 146 ms 16248 KB Output is correct
13 Correct 163 ms 17756 KB Output is correct
14 Correct 173 ms 19512 KB Output is correct
15 Correct 179 ms 20216 KB Output is correct
16 Correct 197 ms 20728 KB Output is correct
17 Correct 185 ms 22136 KB Output is correct
18 Correct 229 ms 20576 KB Output is correct
19 Correct 190 ms 23288 KB Output is correct
20 Correct 148 ms 15864 KB Output is correct
21 Correct 140 ms 16248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9720 KB Output is correct
2 Correct 10 ms 9720 KB Output is correct
3 Correct 11 ms 9756 KB Output is correct
4 Correct 11 ms 9848 KB Output is correct
5 Correct 12 ms 9848 KB Output is correct
6 Correct 11 ms 9852 KB Output is correct
7 Correct 11 ms 9848 KB Output is correct
8 Correct 11 ms 9848 KB Output is correct
9 Correct 11 ms 9848 KB Output is correct
10 Correct 11 ms 9848 KB Output is correct
11 Correct 134 ms 14704 KB Output is correct
12 Correct 146 ms 16248 KB Output is correct
13 Correct 163 ms 17756 KB Output is correct
14 Correct 173 ms 19512 KB Output is correct
15 Correct 179 ms 20216 KB Output is correct
16 Correct 197 ms 20728 KB Output is correct
17 Correct 185 ms 22136 KB Output is correct
18 Correct 229 ms 20576 KB Output is correct
19 Correct 190 ms 23288 KB Output is correct
20 Correct 148 ms 15864 KB Output is correct
21 Correct 140 ms 16248 KB Output is correct
22 Correct 295 ms 23284 KB Output is correct
23 Correct 295 ms 21752 KB Output is correct
24 Correct 303 ms 21924 KB Output is correct
25 Correct 301 ms 26236 KB Output is correct
26 Correct 295 ms 22884 KB Output is correct
27 Correct 294 ms 21752 KB Output is correct
28 Correct 143 ms 12796 KB Output is correct
29 Correct 262 ms 16536 KB Output is correct
30 Correct 249 ms 17144 KB Output is correct
31 Correct 255 ms 16896 KB Output is correct
32 Correct 262 ms 20956 KB Output is correct