Submission #1011876

# Submission time Handle Problem Language Result Execution time Memory
1011876 2024-07-01T10:19:04 Z vjudge1 One-Way Streets (CEOI17_oneway) C++17
100 / 100
71 ms 29372 KB
#include <bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 2e5 + 2;
vector < pair < int , int > > edge;
vector < int > adj[N + 2];
stack < int > st;
vector < pair < int , int >  > g[N + 2];
int f[N + 2];
int low[N + 2] , num[N + 2];
int timer = 0;
int scc  = 0;
bool check[N * 2 + 2];
void add_edge(int u , int v){
    adj[u].push_back(edge.size());
    edge.push_back({u , v});
    adj[v].push_back(edge.size());
    edge.push_back({v , u});
}
void dfs(int u , int id_par = -1){
    low[u] = num[u] = ++timer;
    st.push(u);
    for(auto id: adj[u]){
        if(id_par != -1 && (id ^ id_par) == 1)continue;
        int v = edge[id].second;
        if(num[v]){
            low[u] = min(low[u] , num[v]);
        }
        else{
            dfs(v , id);
            low[u] = min(low[u] , low[v]);
            if(num[u] == low[v]){
                scc++;
                g[u].push_back({scc , -1});
                g[scc].push_back({u  , -1});
                int y;
                while(y != v){
                    y = st.top();
                    st.pop();
                    g[y].push_back({scc , -1});
                    g[scc].push_back({y , -1});
                }
            }
            if(num[u] < low[v]){
                st.pop();
                g[u].push_back({v , id});
                g[v].push_back({u , (id ^ 1)});
            }
        }
    }
}
void dfs2(int u , int id_par = -1 , int p = -1){
    for(auto [v , id] : g[u]){
        if(v == p) continue;
        dfs2(v , id , u);
        f[u] += f[v];
    }
    if(f[u] >  0){
        check[id_par] = 1;
    }
    if(f[u] < 0){
        check[id_par ^ 1] = 1;
    }
}
void solve() {
    int n , m;
    cin >> n >> m;
    scc = n;
    for(int i = 1; i <= m ; i ++){
        int u , v;
        cin >> u >> v;
        add_edge(u , v);
    }
    int q;
    cin >> q;
    while(q -- ){
        int u , v;
        cin >> u >> v;
        f[u] ++;
        f[v] --;
    }
    for(int i  = 1 ; i <= n ; i ++){
        if(!num[i]){
            dfs(i);
            dfs2(i);
        }
    }
    for(int i = 0; i < m ;i  ++){
        if(check[i * 2]) cout << 'L';
        else if(check[i * 2 + 1]) cout <<'R';
        else{
            cout << 'B';
        }
    }
}

signed main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    #define _ "maxseq."
    if (fopen(_ "inp", "r")) {
        freopen(_ "inp", "r", stdin);
        freopen(_ "out", "w", stdout);
    }
    
    solve();
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  103 |         freopen(_ "inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
oneway.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  104 |         freopen(_ "out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:38:25: warning: 'y' may be used uninitialized in this function [-Wmaybe-uninitialized]
   38 |                 while(y != v){
      |                       ~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9640 KB Output is correct
3 Correct 5 ms 9816 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 10016 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9640 KB Output is correct
3 Correct 5 ms 9816 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 10016 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 36 ms 16808 KB Output is correct
12 Correct 38 ms 18372 KB Output is correct
13 Correct 38 ms 20672 KB Output is correct
14 Correct 44 ms 22716 KB Output is correct
15 Correct 44 ms 22972 KB Output is correct
16 Correct 46 ms 20672 KB Output is correct
17 Correct 44 ms 23488 KB Output is correct
18 Correct 47 ms 20924 KB Output is correct
19 Correct 53 ms 25260 KB Output is correct
20 Correct 30 ms 19144 KB Output is correct
21 Correct 33 ms 19140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9640 KB Output is correct
3 Correct 5 ms 9816 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 10016 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9820 KB Output is correct
9 Correct 4 ms 9820 KB Output is correct
10 Correct 4 ms 9820 KB Output is correct
11 Correct 36 ms 16808 KB Output is correct
12 Correct 38 ms 18372 KB Output is correct
13 Correct 38 ms 20672 KB Output is correct
14 Correct 44 ms 22716 KB Output is correct
15 Correct 44 ms 22972 KB Output is correct
16 Correct 46 ms 20672 KB Output is correct
17 Correct 44 ms 23488 KB Output is correct
18 Correct 47 ms 20924 KB Output is correct
19 Correct 53 ms 25260 KB Output is correct
20 Correct 30 ms 19144 KB Output is correct
21 Correct 33 ms 19140 KB Output is correct
22 Correct 59 ms 24492 KB Output is correct
23 Correct 63 ms 21948 KB Output is correct
24 Correct 71 ms 21948 KB Output is correct
25 Correct 59 ms 29372 KB Output is correct
26 Correct 54 ms 24008 KB Output is correct
27 Correct 68 ms 22212 KB Output is correct
28 Correct 24 ms 13648 KB Output is correct
29 Correct 43 ms 19656 KB Output is correct
30 Correct 48 ms 20260 KB Output is correct
31 Correct 45 ms 20416 KB Output is correct
32 Correct 52 ms 24564 KB Output is correct