답안 #380482

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
380482 2021-03-22T03:40:55 Z wind_reaper One-Way Streets (CEOI17_oneway) C++17
0 / 100
4 ms 5484 KB
#include <bits/stdc++.h>

using namespace std;

const int MXN = 100000;

vector<int> adj[MXN], st;

vector<array<int, 2>> bridge_tree[MXN];

int tin[MXN], low[MXN], comp[MXN], timer = 1;

vector<bool> vis(MXN);

void tarjan(int node, int par = -1){
	vis[node] = 1;
	tin[node] = low[node] = timer++;
	st.push_back(node);

	for(int v : adj[node]){
		if(v == par) continue;
		if(vis[v]){
			low[node] = min(low[node], tin[v]);
		}
		else{
			tarjan(v, node);
			low[node] = min(low[node], low[v]);
		}
	}

	if(low[node] == tin[node]){
		int v = -1;
		while(v != node){
			v = st.back();
			st.pop_back();
			comp[v] = node;
		}
	}
}

int ans[MXN], dir[MXN];
vector<array<int, 2>> edges;

void dfs(int node){
	tin[node] = -1;
	for(auto& [v, id] : bridge_tree[node]){
		if(tin[v] < 0)
			continue;
		dfs(v);
		dir[node] += dir[v];
		if(dir[v] == 0) continue;
		if(dir[v] < 0)
			ans[id] = (edges[id][0] == v && edges[id][1] == node) ? 1 : -1;
		else ans[id] = (edges[id][0] == node && edges[id][1] == v) ? 1 : -1;
	}
}

int32_t main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL); 
	
	int n, m;
	cin >> n >> m;

	edges.resize(m);

	for(auto& [u, v] : edges){
		cin >> u >> v;
		--u, --v;
		if(u == v) continue;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	memset(comp, -1, sizeof comp);

	for(int i = 0; i < n; i++){
		if(vis[i]) continue;
		tarjan(i);
	}

	for(int i = 0; i < m; i++){
		auto [u, v] = edges[i];
		u = comp[u], v = comp[v];
		if(u == v) continue;
		bridge_tree[u].push_back({v, i});
		bridge_tree[v].push_back({u, i});
	}

	int p;
	cin >> p;

	for(int i = 0; i < p; i++){
		int u, v;
		cin >> u >> v;
		--u, --v;
		u = comp[u], v = comp[v];
		++dir[u];
		--dir[v];
	}

	for(int i = 0; i < n; i++) if(tin[i] >= 0) dfs(i);

	for(int i = 0; i < m; i++){
		char c = 'B';
		if(ans[i] < 0) c = 'L';
		if(ans[i] > 0) c = 'R';
		cout << c;
	}

	return 0; 
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5484 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 4 ms 5484 KB Output isn't correct
2 Halted 0 ms 0 KB -