답안 #761468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
761468 2023-06-19T18:05:29 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
100 / 100
111 ms 14180 KB
#include <bits/stdc++.h> 
using namespace std; 

typedef long long ll; 

#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)
const int N = 1e5 + 5; 

int n, m, q; 
int U[N], V[N], col, color[N], direction[N], sum[N]; 
bool is_bridge[N]; 
int tin[N], tim, low[N], pa[N]; 
vector <int> adj[N], curr;   
 
void dfs(int u, int f){
    tin[u] = low[u] = ++tim; 
    curr.push_back(u); 
    pa[u] = f; 

    int r = 0;  
    for(int v: adj[u]){
        if(v == f) {r++; continue; } 
        if(tin[v] == 0){
            dfs(v, u); 
            low[u] = min(low[u], low[v]); 
        }
        else low[u] = min(low[u], tin[v]); 
    }
    if(low[u] == tin[u] and r <= 1) {
        col++; 
        while(!curr.empty()){
            int w = curr.back();
            color[w] = col; 
            curr.pop_back(); 
            if(w == u) break; 
        }
        if(f != 0) 
            is_bridge[u] = 1;
    }
}
void DFS(int u, int f){
    tin[u] = ++tim; 
    for(int v: adj[u]){
        if(v == f) continue; 
        if(tin[v] == 0){
            DFS(v, u); 
            sum[u] += sum[v]; 
        }
    }
}
int main(){
    cin >> n >> m; 
    f(i,0,m){
        cin >> U[i] >> V[i]; 
        if(U[i] != V[i]) 
            adj[U[i]].push_back(V[i]), adj[V[i]].push_back(U[i]); 
    }
 
    f(i,1,n+1) if(tin[i] == 0) dfs(i, 0); 
    
    cin >> q; 
    f(i,0,q){
        int u, v; 
        cin >> u >> v; 
        if(color[u] != color[v]) sum[u]++, sum[v]--; 
    }

    tim = 0; 
    f(i,1,n+1) tin[i] = 0; 
    f(i,1,n+1) if(tin[i] == 0) DFS(i, 0); 

    f(i,1,n+1) if(is_bridge[i] and sum[i] != 0) direction[i] = sum[i]/abs(sum[i]); 

    f(i,0,m){
        if((pa[U[i]] == V[i] and direction[U[i]] == 1) or (pa[V[i]] == U[i] and direction[V[i]] == -1)) cout << 'R'; 
        else if((pa[U[i]] == V[i] and direction[U[i]] == -1) or (pa[V[i]] == U[i] and direction[V[i]] == 1)) cout << 'L'; 
        else cout << 'B'; 
    }
    cout << "\n"; 
    return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 52 ms 6744 KB Output is correct
12 Correct 59 ms 7956 KB Output is correct
13 Correct 66 ms 9324 KB Output is correct
14 Correct 79 ms 10488 KB Output is correct
15 Correct 70 ms 10764 KB Output is correct
16 Correct 64 ms 8948 KB Output is correct
17 Correct 71 ms 10916 KB Output is correct
18 Correct 63 ms 9096 KB Output is correct
19 Correct 65 ms 12192 KB Output is correct
20 Correct 60 ms 8032 KB Output is correct
21 Correct 59 ms 7940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 3 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 52 ms 6744 KB Output is correct
12 Correct 59 ms 7956 KB Output is correct
13 Correct 66 ms 9324 KB Output is correct
14 Correct 79 ms 10488 KB Output is correct
15 Correct 70 ms 10764 KB Output is correct
16 Correct 64 ms 8948 KB Output is correct
17 Correct 71 ms 10916 KB Output is correct
18 Correct 63 ms 9096 KB Output is correct
19 Correct 65 ms 12192 KB Output is correct
20 Correct 60 ms 8032 KB Output is correct
21 Correct 59 ms 7940 KB Output is correct
22 Correct 105 ms 10916 KB Output is correct
23 Correct 104 ms 9112 KB Output is correct
24 Correct 111 ms 9116 KB Output is correct
25 Correct 105 ms 14180 KB Output is correct
26 Correct 108 ms 10484 KB Output is correct
27 Correct 102 ms 9204 KB Output is correct
28 Correct 58 ms 4588 KB Output is correct
29 Correct 101 ms 7628 KB Output is correct
30 Correct 99 ms 7824 KB Output is correct
31 Correct 100 ms 8044 KB Output is correct
32 Correct 100 ms 10568 KB Output is correct