답안 #896781

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
896781 2024-01-02T06:14:49 Z qrno One-Way Streets (CEOI17_oneway) C++17
100 / 100
77 ms 16048 KB
#include <bits/stdc++.h>
using namespace std;

int N, M, P;
vector<vector<pair<int, int>>> G;
vector<pair<int, int>> E;

vector<int> req;

int TIMER = -1;
stack<int> S;
vector<int> tin, low;

int cc = -1;
vector<int> C;

void make_comp(int last) {
  cc++;
  int v = -1;
  do {
    v = S.top();
    S.pop();
    C[v] = cc;
  } while (v != last);
}

void tarjan(int v, int pidx) {
  S.push(v);
  tin[v] = low[v] = ++TIMER;
  for (auto [u, eidx] : G[v]) {
    if (eidx == pidx) continue;
    if (tin[u] == -1) {
      tarjan(u, eidx);
      req[v] += req[u];
    }
    low[v] = min(low[v], low[u]);
  }
  if (low[v] == tin[v]) make_comp(v);
}

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

  cin >> N >> M;
  G.resize(N);
  for (int i = 0; i < M; i++) {
    int v, u; cin >> v >> u; v--, u--;
    G[v].push_back({u, i});
    G[u].push_back({v, i});
    E.push_back({v, u});
  }

  req.resize(N);
  cin >> P;
  for (int i = 0; i < P; i++) {
    int v, u; cin >> v >> u; v--, u--;
    req[v]++, req[u]--;
  }

  C.resize(N);
  tin.assign(N, -1);
  low.assign(N, -1);
  for (int i = 0; i < N; i++)
    if (tin[i] == -1)
      tarjan(i, -1);

  string ans(M, '?');
  for (int i = 0; i < M; i++) {
    auto [v, u] = E[i];
    if (C[v] == C[u]) { ans[i] = 'B'; continue; }
    if (tin[v] < tin[u]) {
      if (req[u] > 0) ans[i] = 'L';
      else if (req[u] == 0) ans[i] = 'B';
      else ans[i] = 'R';
    } else {
      if (req[v] > 0) ans[i] = 'R';
      else if (req[v] == 0) ans[i] = 'B';
      else ans[i] = 'L';
    }
  }

  cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 516 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 516 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 23 ms 7120 KB Output is correct
12 Correct 27 ms 8256 KB Output is correct
13 Correct 28 ms 10004 KB Output is correct
14 Correct 45 ms 11564 KB Output is correct
15 Correct 41 ms 11848 KB Output is correct
16 Correct 28 ms 10180 KB Output is correct
17 Correct 28 ms 11680 KB Output is correct
18 Correct 36 ms 10056 KB Output is correct
19 Correct 29 ms 12748 KB Output is correct
20 Correct 30 ms 8564 KB Output is correct
21 Correct 23 ms 8204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 516 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 23 ms 7120 KB Output is correct
12 Correct 27 ms 8256 KB Output is correct
13 Correct 28 ms 10004 KB Output is correct
14 Correct 45 ms 11564 KB Output is correct
15 Correct 41 ms 11848 KB Output is correct
16 Correct 28 ms 10180 KB Output is correct
17 Correct 28 ms 11680 KB Output is correct
18 Correct 36 ms 10056 KB Output is correct
19 Correct 29 ms 12748 KB Output is correct
20 Correct 30 ms 8564 KB Output is correct
21 Correct 23 ms 8204 KB Output is correct
22 Correct 47 ms 12820 KB Output is correct
23 Correct 77 ms 11208 KB Output is correct
24 Correct 39 ms 11208 KB Output is correct
25 Correct 50 ms 16048 KB Output is correct
26 Correct 47 ms 12488 KB Output is correct
27 Correct 42 ms 11208 KB Output is correct
28 Correct 21 ms 4556 KB Output is correct
29 Correct 36 ms 9404 KB Output is correct
30 Correct 39 ms 9368 KB Output is correct
31 Correct 52 ms 9648 KB Output is correct
32 Correct 37 ms 11976 KB Output is correct