답안 #874405

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874405 2023-11-16T22:09:03 Z Tob One-Way Streets (CEOI17_oneway) C++14
100 / 100
67 ms 23908 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]) res[abs(d)] = (x > p) ^ (d > 0) ^ (qu[x] > 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]--;
	}
	
	for (int i = 1; i <= n; i++) {
		if (bio[i]) continue;
		dfs(i);
		dfs2(i);
	}
	
	string s = "LRB";
	
	for (int i = 1; i <= m; i++) cout << s[res[i]];

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6864 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6864 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 28 ms 14680 KB Output is correct
12 Correct 39 ms 15952 KB Output is correct
13 Correct 46 ms 17448 KB Output is correct
14 Correct 49 ms 18288 KB Output is correct
15 Correct 65 ms 18504 KB Output is correct
16 Correct 39 ms 15956 KB Output is correct
17 Correct 41 ms 18260 KB Output is correct
18 Correct 46 ms 16016 KB Output is correct
19 Correct 42 ms 20016 KB Output is correct
20 Correct 32 ms 15960 KB Output is correct
21 Correct 32 ms 15480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 2 ms 6748 KB Output is correct
4 Correct 2 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 2 ms 6748 KB Output is correct
9 Correct 2 ms 6864 KB Output is correct
10 Correct 2 ms 6748 KB Output is correct
11 Correct 28 ms 14680 KB Output is correct
12 Correct 39 ms 15952 KB Output is correct
13 Correct 46 ms 17448 KB Output is correct
14 Correct 49 ms 18288 KB Output is correct
15 Correct 65 ms 18504 KB Output is correct
16 Correct 39 ms 15956 KB Output is correct
17 Correct 41 ms 18260 KB Output is correct
18 Correct 46 ms 16016 KB Output is correct
19 Correct 42 ms 20016 KB Output is correct
20 Correct 32 ms 15960 KB Output is correct
21 Correct 32 ms 15480 KB Output is correct
22 Correct 63 ms 19620 KB Output is correct
23 Correct 63 ms 17248 KB Output is correct
24 Correct 55 ms 16976 KB Output is correct
25 Correct 57 ms 23908 KB Output is correct
26 Correct 67 ms 18976 KB Output is correct
27 Correct 53 ms 17336 KB Output is correct
28 Correct 23 ms 12124 KB Output is correct
29 Correct 54 ms 16436 KB Output is correct
30 Correct 48 ms 16564 KB Output is correct
31 Correct 52 ms 17236 KB Output is correct
32 Correct 48 ms 19796 KB Output is correct