Submission #886396

# Submission time Handle Problem Language Result Execution time Memory
886396 2023-12-12T03:14:49 Z Zero_OP One-Way Streets (CEOI17_oneway) C++14
100 / 100
56 ms 23376 KB
#include<bits/stdc++.h>

using namespace std;

#define range(v) begin(v), end(v)
#define compact(v) v.erase(unique(range(v)), end(v))

template<class T> bool minimize(T& a, T b){
  if(a > b) return a = b, true;
  return false;
}

template<class T> bool maximize(T& a, T b){
  if(a < b) return a = b, true;
  return false;
}

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

const int N = 1e5 + 5;

int n, m, ans[N], low[N], num[N], aNodes[N], bNodes[N], uNodes[N], vNodes[N], id[N], timerDFS, timerSCC;
vector<int> g[N], G[N];
stack<int> st;

void dfsTarjan(int u, int lastID){
  low[u] = num[u] = ++timerDFS;
  st.push(u);
  for(int id : g[u]) if(id != lastID) {
    int v = uNodes[id] ^ vNodes[id] ^ u;
    if(num[v]) minimize(low[u], num[v]);
    else{
      dfsTarjan(v, id);
      minimize(low[u], low[v]);
    }
  }

  if(low[u] == num[u]){
    ++timerSCC;
    do{
      int v = st.top(); st.pop();
      low[v] = num[v] = N;
      id[v] = timerSCC;
    } while(!id[u]);
  }
}

int h[N], dp[N];
bool vst[N];

void dfsSolve(int u, int lastID){
  vst[u] = true;
  for(int id : G[u]) if(id != lastID){
    int v = aNodes[id] ^ bNodes[id] ^ u;
    dfsSolve(v, id);
    dp[u] += dp[v];

    if(dp[v] == 0){
      ans[id] = 0;
    }
    else if(dp[v] > 0){
      if(v == aNodes[id]) ans[id] = 1;
      else ans[id] = 2;
    }
    else{
      if(v == aNodes[id]) ans[id] = 2;
      else ans[id] = 1;
    }
  }
}

void Zero_OP(){
  cin >> n >> m;
  for(int i = 1; i <= m; ++i){
    int u, v;
    cin >> u >> v;
    uNodes[i] = u, vNodes[i] = v;
    g[u].push_back(i);
    g[v].push_back(i);
  }

  for(int i = 1; i <= n; ++i){
    if(!num[i]){
      dfsTarjan(i, -1);
    }
  }

  for(int i = 1; i <= m; ++i){
    int u = uNodes[i], v = vNodes[i];
    aNodes[i] = id[u], bNodes[i] = id[v];
    if(id[u] != id[v]){
      ans[i] = -1;
      G[id[u]].push_back(i);
      G[id[v]].push_back(i);
    }
    else ans[i] = 0;
  }

  int q; cin >> q;
  while(q--){
    int x, y;
    cin >> x >> y;
    x = id[x], y = id[y];
    ++dp[x];
    --dp[y];
  }

  for(int i = 1; i <= timerSCC; ++i){
    if(!vst[i]){
      dfsSolve(i, -1);
    }
  }

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

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

  #define task "antuvu"
  if(fopen(task".inp", "r")){
    freopen(task".inp", "r", stdin);
    freopen(task".out", "w", stdout);
  }

  Zero_OP();

  return 0;
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:129:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  129 |     freopen(task".inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:130:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  130 |     freopen(task".out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8788 KB Output is correct
11 Correct 24 ms 13140 KB Output is correct
12 Correct 28 ms 14248 KB Output is correct
13 Correct 32 ms 15184 KB Output is correct
14 Correct 38 ms 16212 KB Output is correct
15 Correct 36 ms 16476 KB Output is correct
16 Correct 42 ms 16720 KB Output is correct
17 Correct 38 ms 18736 KB Output is correct
18 Correct 40 ms 16744 KB Output is correct
19 Correct 38 ms 20052 KB Output is correct
20 Correct 27 ms 13648 KB Output is correct
21 Correct 26 ms 13300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8540 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 2 ms 8540 KB Output is correct
5 Correct 2 ms 8540 KB Output is correct
6 Correct 2 ms 8536 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 3 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8788 KB Output is correct
11 Correct 24 ms 13140 KB Output is correct
12 Correct 28 ms 14248 KB Output is correct
13 Correct 32 ms 15184 KB Output is correct
14 Correct 38 ms 16212 KB Output is correct
15 Correct 36 ms 16476 KB Output is correct
16 Correct 42 ms 16720 KB Output is correct
17 Correct 38 ms 18736 KB Output is correct
18 Correct 40 ms 16744 KB Output is correct
19 Correct 38 ms 20052 KB Output is correct
20 Correct 27 ms 13648 KB Output is correct
21 Correct 26 ms 13300 KB Output is correct
22 Correct 51 ms 19668 KB Output is correct
23 Correct 56 ms 17744 KB Output is correct
24 Correct 54 ms 18000 KB Output is correct
25 Correct 52 ms 23376 KB Output is correct
26 Correct 50 ms 19284 KB Output is correct
27 Correct 52 ms 17876 KB Output is correct
28 Correct 21 ms 11348 KB Output is correct
29 Correct 38 ms 14368 KB Output is correct
30 Correct 37 ms 14564 KB Output is correct
31 Correct 39 ms 14944 KB Output is correct
32 Correct 41 ms 17964 KB Output is correct