답안 #115211

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
115211 2019-06-06T04:31:55 Z IOrtroiii One-Way Streets (CEOI17_oneway) C++14
0 / 100
6 ms 5120 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 100100;

int n, m, q;
bool visit[N];
int p[N], ans[N];
vector<pair<int, int>> g[N];
vector<pair<int, int>> g2[N];
int num[N], low[N], tt;
int par[N], parid[N], dep[N];
vector<tuple<int, int, int>> tr;

int getp(int u) {
   if (p[u] == u) {
      return u;
   } else {
      return p[u] = getp(p[u]);
   }
}

void mrg(int u, int v) {
   p[getp(v)] = getp(u);
}

void dfs(int u, int pid) {
   num[u] = low[u] = ++tt;
   for (auto e : g[u]) {
      int v, id; tie(v, id) = e;
      if (id + pid) {
         if (num[v]) low[u] = min(low[u], num[v]);
         else {
            dfs(v, id);
            low[u] = min(low[u], low[v]);
            if (low[v] > num[u]) {
               tr.emplace_back(u, v, id);
            } else mrg(u, v);
         }
      }
   }
}

void dfs2(int u, int p) {
   visit[u] = true;
   for (auto e : g2[u]) {
      int v, id; tie(v, id) = e;
      if (v ^ p) {
         par[v] = u;
         parid[v] = -id;
         dep[v] = dep[u] + 1;
         dfs2(v, u);
      }
   }
}

int main() {
   scanf("%d %d", &n, &m);
   for (int i = 1; i <= n; ++i) p[i] = i;
   for (int i = 1; i <= m; ++i) {
      int u, v;
      scanf("%d %d", &u, &v);
      g[u].emplace_back(v, i);
      g[v].emplace_back(u, -i);
   }
   for (int i = 1; i <= n; ++i) {
      if (!num[i]) dfs(i, 0);
   }
   for (auto e : tr) {
      int u, v, id; tie(u, v, id) = e;
      u = getp(u), v = getp(v);
      g2[u].emplace_back(v, id);
      g2[v].emplace_back(u, -id);
   }
   for (int i = 1; i <= n; ++i) {
      if (p[i] == i && !visit[i]) dfs2(i, 0);
   }
   scanf("%d", &q);
   while (q--) {
      int u, v;
      scanf("%d %d", &u, &v);
      u = getp(u), v = getp(v);
      while (u ^ v) {
         if (dep[u] > dep[v]) {
            if (parid[u] > 0) ans[parid[u]] = 1;
            else ans[-parid[u]] = 2;
            mrg(par[u], u);
            u = getp(u);
         } else {
            if (parid[v] > 0) ans[parid[v]] = 2;
            else ans[-parid[v]] = 1;
            mrg(par[v], v);
            v = getp(v);
         }
      }
   }
   for (int i = 1; i <= m; ++i) {
      if (ans[i] == 0) putchar('B');
      else if (ans[i] == 1) putchar('L');
      else putchar('R');
   }
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:59:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &n, &m);
    ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:63:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &u, &v);
       ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:79:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &q);
    ~~~~~^~~~~~~~~~
oneway.cpp:82:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d %d", &u, &v);
       ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 6 ms 5120 KB Output isn't correct
2 Halted 0 ms 0 KB -