Submission #1027475

# Submission time Handle Problem Language Result Execution time Memory
1027475 2024-07-19T06:51:25 Z khanhtb One-Way Streets (CEOI17_oneway) C++14
100 / 100
63 ms 25028 KB
#include <bits/stdc++.h>
#define ll int
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9 + 7;
const ll inf = 2e18;
const ll blocksz = 320;
const ll N = 1e5 + 8;
ll num[N],low[N],tdfs,m,n,q;
bool vst[N];
vpll adj[N];
bool bridge[N];
vpll edge = {{0,0}};
void dfs_bridge(ll u, ll p){
    num[u] = low[u] = ++tdfs;
    for(pll ed:adj[u]){
        ll v = ed.fi, id = ed.se;
        if(v == p) continue;
        if(!num[v]){
            dfs_bridge(v,u);
            low[u] = min(low[u],low[v]);
            if(low[v] == num[v]){
                bridge[id] = 1;
            }
        }
        else low[u] = min(low[u],num[v]);
    }
}
ll cc[N],cntcc;
void dfs_component(ll u){
    cc[u] = cntcc;
    vst[u] = 1;
    for(pll ed:adj[u]){
        ll v = ed.fi, id = ed.se;
        if(bridge[id]) continue;
        if(vst[v]) continue;
        dfs_component(v);
    }
}
struct node{
    ll v,id,x,y;
};
vector<node> g[N];
void build(){
    for(ll i = 1; i <= n; i++) if(!num[i]) tdfs = 0, dfs_bridge(i,i);
    for(ll i = 1; i <= n; i++) if(!vst[i]) cntcc++,dfs_component(i);
    for(ll i = 1; i <= m; i++){
        ll u = edge[i].fi, v = edge[i].se;
        if(bridge[i]){
            g[cc[u]].pb({cc[v],i,u,v});
            g[cc[v]].pb({cc[u],i,v,u});
        }
    }
}
ll dp[N];
pll ans[N];
void direct(ll u, ll p){
    vst[u] = 1;
    for(node v:g[u]){
        if(v.v == p || vst[v.v]) continue;
        v.x = u, v.y = v.v;
        direct(v.v,u);
    }
}
void dfs(ll u, ll p) {
    vst[u] = 1;
    for(node v:g[u]){
        if(v.v == p || vst[v.v]) continue;
        dfs(v.v, u);
        dp[u] += dp[v.v];
        if(dp[v.v] > 0) ans[v.id] = {v.y, v.x};
        if(dp[v.v] < 0) ans[v.id] = {v.x, v.y};
    }
}
void solve(){
    cin >> n >> m;
    for(ll i = 1; i <= m; i++){
        ans[i] = {-1,-1};
        ll u,v;cin >> u >> v;
        adj[u].pb({v,i});
        adj[v].pb({u,i});
        edge.pb({u,v});
    }
    build();
    fill(vst,vst+n+1,0);
    for(ll i = 1; i <= n; i++) if(!vst[i]) direct(i,i); 
    cin >> q;
    while(q--){
        ll u,v;cin >> u >> v;
        dp[cc[u]]++;
        dp[cc[v]]--;
    }
    fill(vst,vst+n+1,0);
    for(ll i = 1; i <= n; i++) if(!vst[i]) dfs(i,i);
    for(ll i = 1; i <= m; i++) {
        if(ans[i].fi < 0 || !bridge[i]) cout << "B";
        else cout << (ans[i] == edge[i] ? "R" : "L");
    }
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll T = 1;
    // cin >> T;
    for (ll i = 1; i <= T; i++){
        solve();
        cout << '\n';
    }
}

Compilation message

oneway.cpp:16:16: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
   16 | const ll inf = 2e18;
      |                ^~~~
oneway.cpp: In function 'int main()':
oneway.cpp:115:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  115 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:116:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 26 ms 12736 KB Output is correct
12 Correct 32 ms 13764 KB Output is correct
13 Correct 34 ms 14896 KB Output is correct
14 Correct 40 ms 15924 KB Output is correct
15 Correct 42 ms 16580 KB Output is correct
16 Correct 54 ms 18580 KB Output is correct
17 Correct 46 ms 20164 KB Output is correct
18 Correct 48 ms 18504 KB Output is correct
19 Correct 47 ms 21704 KB Output is correct
20 Correct 28 ms 13300 KB Output is correct
21 Correct 28 ms 13000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6492 KB Output is correct
7 Correct 1 ms 6748 KB Output is correct
8 Correct 3 ms 6748 KB Output is correct
9 Correct 2 ms 6488 KB Output is correct
10 Correct 1 ms 6488 KB Output is correct
11 Correct 26 ms 12736 KB Output is correct
12 Correct 32 ms 13764 KB Output is correct
13 Correct 34 ms 14896 KB Output is correct
14 Correct 40 ms 15924 KB Output is correct
15 Correct 42 ms 16580 KB Output is correct
16 Correct 54 ms 18580 KB Output is correct
17 Correct 46 ms 20164 KB Output is correct
18 Correct 48 ms 18504 KB Output is correct
19 Correct 47 ms 21704 KB Output is correct
20 Correct 28 ms 13300 KB Output is correct
21 Correct 28 ms 13000 KB Output is correct
22 Correct 59 ms 21440 KB Output is correct
23 Correct 63 ms 19604 KB Output is correct
24 Correct 63 ms 19760 KB Output is correct
25 Correct 60 ms 25028 KB Output is correct
26 Correct 59 ms 20900 KB Output is correct
27 Correct 59 ms 19628 KB Output is correct
28 Correct 22 ms 10952 KB Output is correct
29 Correct 41 ms 13872 KB Output is correct
30 Correct 39 ms 14020 KB Output is correct
31 Correct 42 ms 14276 KB Output is correct
32 Correct 45 ms 18120 KB Output is correct