답안 #706905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
706905 2023-03-08T06:20:28 Z mychecksedad One-Way Streets (CEOI17_oneway) C++17
0 / 100
3 ms 4948 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1e5+100, M = 1e5+10, K = 20;


int n, m, p, tin[N], tout[N], up[N][K], par[N][2], lo[N], timer = 0, ti[N];
vector<pair<int, int>> g[N], f[N];
vector<bool> vis, bridge;
string s;

void st(int v){
  vis[v] = 1;
  for(auto U: g[v]){
    int u = U.first, idx = U.second;
    if(!vis[u]){
      f[v].pb({u, idx});
      f[u].pb({v, idx^1});
      par[u][0] = v;
      par[u][1] = idx;
      st(u);
    }
  }
}

void pre(int v, int p){
  tin[v] = timer++;
  for(auto U: f[v]){
    int u = U.first;
    if(u != p){
      up[u][0] = v, pre(u, v);
    }
  }
  tout[v] = timer++;
}

bool is_ancestor(int u, int v){
  return tin[u] <= tin[v] && tout[v] <= tout[u];
}

int _lca(int u, int v){
  if(is_ancestor(u, v)) return u;
  if(is_ancestor(v, u)) return v;
  for(int j = K - 1; j >= 0 ;--j){
    if(!is_ancestor(up[u][j], v)) u = up[u][j];
  }
  return up[u][0];
}


void bf(int v, int pp){
  ti[v] = lo[v] = timer++;
  vis[v] = 1;
  for(auto U: g[v]){
    int u = U.first, idx = U.second;
    if(idx/2 == pp/2) continue;
    if(vis[u]){
      lo[v] = min(lo[v], ti[u]);
    }else{
      bf(u, idx);
      lo[v] = min(lo[v], lo[u]);
      if(lo[u] > ti[v]){
        bridge[idx>>1] = 1;
      }
    }
  }
}

void solve(){
  cin >> n >> m;
  for(int i = 0 ; i < m; ++i){
    int u, v; cin >> u >> v;
    g[u].pb({v, i*2});
    g[v].pb({u, i*2+1});
    s += 'B';
  }
  vis.resize(n + 1);
  st(1);
  pre(1, 0);
  up[1][0] = 1;
  for(int j = 1; j < K; ++j) for(int i = 1; i <= n; ++i) up[i][j] = up[up[i][j - 1]][j - 1];

  vis.clear();
  vis.resize(n + 1, 0);
  bridge.resize(m, 0);
  timer = 0;
  bf(1, -1);

  vis.clear();
  vis.resize(m, 0);

  cin >> p;
  for(int i = 0; i < p; ++i){
    int u, v; cin >> u >> v;
    int lca = _lca(u, v);
    while(v != lca){
      if(vis[par[v][1]>>1]) break;
      vis[par[v][1]>>1] = 1;
      if(bridge[par[v][1]>>1])
        s[par[v][1]>>1] = ((par[v][1] & 1) ^ 1) ? 'R' : 'L';
      v = par[v][0];
    }

    while(u != lca){
      if(vis[par[u][1]>>1]) break;
      vis[par[u][1]>>1] = 1;
      if(bridge[par[u][1]>>1])
        s[par[u][1]>>1] = (par[u][1] & 1) ? 'R' : 'L';
      u = par[u][0];
    }
  }
  cout << s;
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int T = 1, aa;
  // cin >> T;aa=T;
  while(T--){
    // cout << "Case #" << aa-T << ": ";
    solve();
    cout << '\n';
  }
  return 0;
 
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:124:14: warning: unused variable 'aa' [-Wunused-variable]
  124 |   int T = 1, aa;
      |              ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -