Submission #1085532

# Submission time Handle Problem Language Result Execution time Memory
1085532 2024-09-08T11:43:16 Z juicy One-Way Streets (CEOI17_oneway) C++17
0 / 100
1 ms 6748 KB
#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

const int N = 1e5 + 5;

int n, m, p;
int low[N], num[N], lab[N], a[N], ind[N];
vector<int> g[N];
vector<array<int, 2>> tr[N];

int timer;
vector<int> st;

void dfs(int u, int p) {
  low[u] = num[u] = ++timer;
  st.push_back(u);
  bool rep = 0;
  for (int v : g[u]) {
    if (v == p && !rep) {
      rep = 1;
      continue;
    } 
    if (!low[v]) {
      dfs(v, u);
      low[u] = min(low[u], low[v]);
    } else {
      low[u] = min(low[u], num[v]);
    }
  }
  if (low[u] == num[u]) {
    while (1) {
      int v = st.back(); st.pop_back();
      lab[v] = u;
      if (v == u) {
        break;
      }
    }
  }
}

void DFS(int u, int p) {
  for (auto [v, id] : tr[u]) {
    if (v ^ p) {
      ind[v] = id;
      DFS(v, u);
      a[u] += a[v];
    }
  }
}

int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  string res(m, 'B');
  vector<array<int, 2>> e(m);
  for (int i = 0; i < m; ++i) {
    int u, v; cin >> u >> v;
    e[i] = {u, v};
    g[u].push_back(v);
    g[v].push_back(u);
  }  
  dfs(1, 1);
  for (int i = 0; i < m; ++i) {
    auto [u, v] = e[i];
    tie(u, v) = tie(lab[u], lab[v]);
    if (u ^ v) {
      tr[u].push_back({v, -1 - i});
      tr[v].push_back({u, i + 1});
    }
  }
  cin >> p;
  while (p--) {
    int x, y; cin >> x >> y;
    ++a[lab[x]], --a[lab[y]];
  }
  DFS(1, 1);
  for (int i = 2; i <= n; ++i) {
    if (a[i]) {
      bool r = (a[i] > 0) ^ (ind[i] < 0);
      int id = abs(ind[i]) - 1;
      res[id] = r ? 'R' : 'L';
    }
  }
  cout << res;
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6748 KB Output isn't correct
2 Halted 0 ms 0 KB -