답안 #199361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
199361 2020-01-31T16:14:56 Z nvmdava One-Way Streets (CEOI17_oneway) C++17
100 / 100
487 ms 57336 KB
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define ff first
#define ss second
#define N 100005
#define MOD 1000000007

vector<int> adj[N];
int v[N], u[N];
int dsu[N];
int dep[N], low[N];
int ans[N];

int find(int x){
    return x == dsu[x] ? x : dsu[x] = find(dsu[x]);
}
void merge(int a, int b){
    dsu[find(a)] = find(b);
}

int proc[N];

void dfs(int v, int p){
    ++proc[v];
    low[v] = dep[v] = dep[::v[p] ^ ::u[p] ^ v] + 1;
    
    for(auto& x : adj[v]){
        if(x == p) continue;
        int u = ::v[x] ^ ::u[x] ^ v;
        if(!dep[u])
            dfs(u, x);
        low[v] = min(low[v], low[u]);
    }
    if(low[v] != dep[v])
        merge(v, ::v[p] ^ ::u[p] ^ v);
}

map<int, int> in[N];

void dfs2(int v, int p){
    ++proc[v];
    for(auto& x : adj[v]){
        if(x == p) continue;
        int u = ::v[x] ^ ::u[x] ^ v;
        dfs2(u, x);
        if(in[v].size() < in[u].size())
            swap(in[v], in[u]);
    }

    for(auto& x : adj[v]){
        if(x == p) continue;
        int u = ::v[x] ^ ::u[x] ^ v;
        for(auto& y : in[u]){
            if((in[v][y.ff] += y.ss) == 3)
                in[v].erase(y.ff);
        }
    }
    if(!in[v].empty()){
        int val = in[v].begin() -> ss - 1;
        if(val ^ (v == ::v[p]) == 1)
            ans[p] = 1;
        else
            ans[p] = 2;
    }
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n, m;
    cin>>n>>m;
    for(int i = 1; i <= m; ++i){
        cin>>v[i]>>u[i];
        adj[v[i]].push_back(i);
        adj[u[i]].push_back(i);
    }

    for(int i = 1; i <= n; ++i)
        dsu[i] = i;
    
    for(int i = 1; i <= n; ++i)
        if(proc[i] == 0)
            dfs(i, 0);

    for(int i = 1; i <= n; ++i)
        adj[i].clear();
    for(int i = 1; i <= m; ++i){
        v[i] = find(v[i]);
        u[i] = find(u[i]);
        if(v[i] != u[i]){
            adj[v[i]].push_back(i);
            adj[u[i]].push_back(i);
        }
    }

    int p;
    cin>>p;

    while(p--){
        int a, b;
        cin>>a>>b;
        a = find(a);
        b = find(b);
        if(a != b){
            in[a][p] = 1;
            in[b][p] = 2;
        }
    }

    for(int i = 1; i <= n; ++i)
        if(proc[find(i)] == 1)
            dfs2(find(i), 0);

    for(int i = 1; i <= m; ++i)
        if(ans[i] == 0)
            cout<<"B";
        else if(ans[i] == 2)
            cout<<"L";
        else
            cout<<"R";
}

Compilation message

oneway.cpp: In function 'void dfs2(int, int)':
oneway.cpp:62:32: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
         if(val ^ (v == ::v[p]) == 1)
                  ~~~~~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 12 ms 7544 KB Output is correct
4 Correct 10 ms 7544 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7544 KB Output is correct
7 Correct 10 ms 7544 KB Output is correct
8 Correct 10 ms 7544 KB Output is correct
9 Correct 10 ms 7420 KB Output is correct
10 Correct 12 ms 7416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 12 ms 7544 KB Output is correct
4 Correct 10 ms 7544 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7544 KB Output is correct
7 Correct 10 ms 7544 KB Output is correct
8 Correct 10 ms 7544 KB Output is correct
9 Correct 10 ms 7420 KB Output is correct
10 Correct 12 ms 7416 KB Output is correct
11 Correct 59 ms 12372 KB Output is correct
12 Correct 72 ms 13432 KB Output is correct
13 Correct 102 ms 14712 KB Output is correct
14 Correct 111 ms 15864 KB Output is correct
15 Correct 122 ms 16120 KB Output is correct
16 Correct 131 ms 14312 KB Output is correct
17 Correct 103 ms 17272 KB Output is correct
18 Correct 133 ms 14700 KB Output is correct
19 Correct 102 ms 19064 KB Output is correct
20 Correct 73 ms 13432 KB Output is correct
21 Correct 66 ms 13560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 12 ms 7544 KB Output is correct
4 Correct 10 ms 7544 KB Output is correct
5 Correct 10 ms 7544 KB Output is correct
6 Correct 10 ms 7544 KB Output is correct
7 Correct 10 ms 7544 KB Output is correct
8 Correct 10 ms 7544 KB Output is correct
9 Correct 10 ms 7420 KB Output is correct
10 Correct 12 ms 7416 KB Output is correct
11 Correct 59 ms 12372 KB Output is correct
12 Correct 72 ms 13432 KB Output is correct
13 Correct 102 ms 14712 KB Output is correct
14 Correct 111 ms 15864 KB Output is correct
15 Correct 122 ms 16120 KB Output is correct
16 Correct 131 ms 14312 KB Output is correct
17 Correct 103 ms 17272 KB Output is correct
18 Correct 133 ms 14700 KB Output is correct
19 Correct 102 ms 19064 KB Output is correct
20 Correct 73 ms 13432 KB Output is correct
21 Correct 66 ms 13560 KB Output is correct
22 Correct 404 ms 39032 KB Output is correct
23 Correct 448 ms 53240 KB Output is correct
24 Correct 487 ms 57336 KB Output is correct
25 Correct 392 ms 38648 KB Output is correct
26 Correct 431 ms 38252 KB Output is correct
27 Correct 476 ms 44792 KB Output is correct
28 Correct 49 ms 10488 KB Output is correct
29 Correct 170 ms 23288 KB Output is correct
30 Correct 261 ms 26876 KB Output is correct
31 Correct 113 ms 18168 KB Output is correct
32 Correct 338 ms 30208 KB Output is correct