Submission #1081046

#TimeUsernameProblemLanguageResultExecution timeMemory
1081046PanosPaskOne-Way Streets (CEOI17_oneway)C++14
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> #define pb push_back #define mp make_pair using namespace std; typedef pair<int, int> pi; const int MAXUP = 20; int N, M, P; vector<vector<int>> adj_list; vector<pi> edges; /* dp[node]: * Number of back edges between node and par[node] */ vector<int> dp; vector<vector<int>> ancestor; vector<int> dep; vector<int> upwards, downwards; void dfs(int node, int par) { ancestor[0][node] = par; dp[node] = 0; for (auto neigh : adj_list[node]) { if (neigh == par) { par = -1; continue; } if (dep[neigh] == -1) { dep[neigh] = dep[node] + 1; dfs(neigh, node); dp[node] += dp[neigh]; } else { // This is a back edge if (dep[neigh] < dep[node]) { dp[node]++; } else { dp[node]--; } } } } void propagate(int node, int par) { for (auto neigh : adj_list[node]) { if (dep[neigh] == dep[node] + 1) { propagate(neigh, node); upwards[node] += upwards[neigh]; downwards[node] += downwards[neigh]; } } } int jump(int a, int v) { for (int up = 0; up < MAXUP; up++) { if (v & (1 << up)) { a = ancestor[up][a]; } } return a; } int lca(int a, int b) { if (dep[a] < dep[b]) { swap(a, b); } a = jump(a, dep[a] - dep[b]); if (a == b) { return a; } for (int up = MAXUP - 1; up >= 0; up--) { int n_a = ancestor[up][a]; int n_b = ancestor[up][b]; if (n_a != n_b) { a = n_a; b = n_b; } } return ancestor[0][a]; } void precalculate(void) { for (int up = 1; up < MAXUP; up++) { for (int i = 0; i < N; i++) { ancestor[up][i] = ancestor[up - 1][ancestor[up - 1][i]]; } } } int main(void) { scanf("%d %d", &N, &M); adj_list.resize(N); ancestor.resize(MAXUP, vector<int>(N)); dep.assign(N, -1); upwards.assign(N, 0); downwards.assign(N, 0); dp.resize(N); for (int i = 0; i < M; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; adj_list[u].pb(v); adj_list[v].pb(u); edges.pb(mp(u, v)); } dep[0] = 0; dfs(0, 0); precalculate(); scanf("%d", &P); for (int i = 0; i < P; i++) { int u, v; scanf("%d %d", &u, &v); u--; v--; int l = lca(u, v); upwards[u]++; downwards[v]++; upwards[l]--; downwards[l]--; } propagate(0, 0); for (auto [u, v] : edges) { int swaped = 0; if (dep[u] > dep[v]) { swap(u, v); swaped = 1; } if (dep[v] != dep[u] + 1 || dp[v] != 0) { printf("B"); } else { if (upwards[v] == 0 && downwards[v] == 0) { printf("B"); } else if (upwards[v] ^ swaped) { printf("L"); } else { printf("R"); } } } printf("\n"); }

Compilation message (stderr)

oneway.cpp: In function 'int main()':
oneway.cpp:148:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  148 |     for (auto [u, v] : edges) {
      |               ^
oneway.cpp:109:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |     scanf("%d %d", &N, &M);
      |     ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:120:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  120 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:132:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  132 |     scanf("%d", &P);
      |     ~~~~~^~~~~~~~~~
oneway.cpp:135:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  135 |         scanf("%d %d", &u, &v);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...