답안 #575551

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
575551 2022-06-11T00:43:08 Z thiago_bastos One-Way Streets (CEOI17_oneway) C++17
100 / 100
111 ms 27448 KB
#include <bits/stdc++.h>

using namespace std;

using i64 = long long;
using u64 = unsigned long long;
using ld = long double;
using ii = pair<int, int>;

const int N = 1e5 + 100;

int n, m, q, in[N], out[N], low[N], t, dir[N];

bool flag[N];
vector<tuple<int, int, int>> g[N];

vector<int> to[N], from[N];
ii mi[N], ma[N];

void preProcess(int u, int p = -1) {
	in[u] = out[u] = t++;
	for(auto [v, e, f] : g[u]) {
		if(in[v] < 0) {
			preProcess(v, u);
			out[u] = out[v];
		}
	}
}

void dfs(int u, int p = -1) {
	low[u] = t++;

	mi[u] = ii(n, -1);
	ma[u] = ii(-1, -1);

	for(auto [v, e, f] : g[u]) {
		if(low[v] < 0) {
			dfs(v, u);
          
			mi[u] = min(mi[u], mi[v]);
			ma[u] = max(ma[u], ma[v]);

			if(low[v] > in[u]) {
				if(mi[v].first < in[v]) {
					auto [t, ff] = mi[v];
					dir[e] = f * ff;
				}
				if(ma[v].first > out[v]) {
					auto [t, ff] = ma[v];
					dir[e] = f * ff;
				}
			}

			low[u] = min(low[u], low[v]);
		} else {
			if(!(v == p && !flag[u])) low[u] = min(low[u], in[v]); 
			if(v == p) flag[u] = true;
		}
	}
	
	for(int v : to[u]) {
		mi[u] = min(mi[u], ii(in[v], -1));
		ma[u] = max(ma[u], ii(in[v], -1));
	}

	for(int v : from[u]) {
		mi[u] = min(mi[u], ii(in[v], 1));
		ma[u] = max(ma[u], ii(in[v], 1));
	}
}

void solve() {
	cin >> n >> m;

	memset(in, -1, sizeof(int) * n);
	memset(low, -1, sizeof(int) * n);

	for(int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		--u, --v;
		if(u != v) {
			g[u].emplace_back(v, i, 1);
			g[v].emplace_back(u, i, -1);
		}
	}

	cin >> q;

	while(q--) {
		int x, y;
		cin >> x >> y;
		--x, --y;
		to[x].push_back(y);
		from[y].push_back(x);
	}

	for(int i = 0; i < n; ++i) if(in[i] < 0) preProcess(i);
	t = 0;
	for(int i = 0; i < n; ++i) if(low[i] < 0) dfs(i);

	string ans;

	for(int i = 0; i < m; ++i) {
		if(dir[i] == -1) ans += 'L';
		else if(dir[i] == 1) ans += 'R';
		else ans += 'B';
	}

	cout << ans << '\n';
}

int main() {
	ios_base :: sync_with_stdio(false);
	cin.tie(0);
	int t = 1;
	//cin >> t;
	while(t--) solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 4 ms 7368 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 4 ms 7396 KB Output is correct
5 Correct 6 ms 7516 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 5 ms 7636 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 4 ms 7368 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 4 ms 7396 KB Output is correct
5 Correct 6 ms 7516 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 5 ms 7636 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 35 ms 15052 KB Output is correct
12 Correct 48 ms 16484 KB Output is correct
13 Correct 54 ms 18132 KB Output is correct
14 Correct 64 ms 19168 KB Output is correct
15 Correct 72 ms 19180 KB Output is correct
16 Correct 62 ms 15908 KB Output is correct
17 Correct 58 ms 18756 KB Output is correct
18 Correct 62 ms 16244 KB Output is correct
19 Correct 57 ms 20544 KB Output is correct
20 Correct 45 ms 15872 KB Output is correct
21 Correct 44 ms 15944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 7380 KB Output is correct
2 Correct 4 ms 7368 KB Output is correct
3 Correct 4 ms 7508 KB Output is correct
4 Correct 4 ms 7396 KB Output is correct
5 Correct 6 ms 7516 KB Output is correct
6 Correct 4 ms 7508 KB Output is correct
7 Correct 5 ms 7636 KB Output is correct
8 Correct 4 ms 7380 KB Output is correct
9 Correct 4 ms 7380 KB Output is correct
10 Correct 4 ms 7380 KB Output is correct
11 Correct 35 ms 15052 KB Output is correct
12 Correct 48 ms 16484 KB Output is correct
13 Correct 54 ms 18132 KB Output is correct
14 Correct 64 ms 19168 KB Output is correct
15 Correct 72 ms 19180 KB Output is correct
16 Correct 62 ms 15908 KB Output is correct
17 Correct 58 ms 18756 KB Output is correct
18 Correct 62 ms 16244 KB Output is correct
19 Correct 57 ms 20544 KB Output is correct
20 Correct 45 ms 15872 KB Output is correct
21 Correct 44 ms 15944 KB Output is correct
22 Correct 100 ms 22620 KB Output is correct
23 Correct 104 ms 20140 KB Output is correct
24 Correct 102 ms 20172 KB Output is correct
25 Correct 111 ms 27448 KB Output is correct
26 Correct 108 ms 21984 KB Output is correct
27 Correct 98 ms 20188 KB Output is correct
28 Correct 29 ms 12620 KB Output is correct
29 Correct 78 ms 18900 KB Output is correct
30 Correct 75 ms 19388 KB Output is correct
31 Correct 88 ms 19640 KB Output is correct
32 Correct 81 ms 23316 KB Output is correct