답안 #874404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874404 2023-11-16T21:56:45 Z Tob One-Way Streets (CEOI17_oneway) C++14
0 / 100
2 ms 6900 KB
#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef pair <ll, ll> pii;

const int N = 1e5 + 7;

int n, m, q, tim;
int bio[N], st[N], ba[N], res[N], qu[N];
vector <pii> adj[N], gadj[N];

void dfs(int x, int p = 0, int d = 0) {
	bio[x] = 1;
	st[x] = ++tim;
	ba[x] = st[x];
	for (auto y : adj[x]) {
		if (y.S == d) continue;
		if (bio[y.F]) {
			ba[x] = min(ba[x], st[y.F]);
			res[abs(y.S)] = 2;
//			cout << x << " " << abs(y.S) << "\n";
			continue;
		}
		dfs(y.F, x, y.S);
		ba[x] = min(ba[x], ba[y.F]);
		gadj[x].pb(y);
	}
}

void dfs2(int x, int p = 0, int d = 0) {
	for (auto it : gadj[x]) {
//		cout << x << " " << it.F << " " << abs(it.S) << "\n";
		dfs2(it.F, x, it.S);
		qu[x] += qu[it.F];
	}
	if (x == 1) return;
	if (ba[x] < st[x]) {
		res[abs(d)] = 2;
		return;
	}
		
	if (qu[x] < 0) res[abs(d)] = (x > p) ^ (d > 0);
	else if (qu[x] > 0) res[abs(d)] = (x < p) ^ (d > 0);
	else res[abs(d)] = 2;
}

int main () {
	FIO;
	cin >> n >> m;
	
	for (int i = 1; i <= m; i++) {
		int x, y; cin >> x >> y;
		int o = 1 - 2*(x < y);
		adj[x].pb({y, i*o});
		adj[y].pb({x, i*o});
	}
	
	cin >> q;
	
	while (q--) {
		int x, y; cin >> x >> y;
		qu[x]++;
		qu[y]--;
	}
	
	dfs(1);
	dfs2(1);
	
	string s = "LRB";
	
	for (int i = 1; i <= m; i++) cout << s[res[i]];

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