Submission #570053

# Submission time Handle Problem Language Result Execution time Memory
570053 2022-05-28T13:47:30 Z jesus_coconut One-Way Streets (CEOI17_oneway) C++17
100 / 100
373 ms 49600 KB
#include <bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define all(a) begin(a), end(a)
#define F first
#define S second

using namespace std;

int const N = 100005;

int n, m, p;
vector<vector<pair<int, int>>> adj;
vector<set<pair<int, int>>> vp;
vector<pair<int, int>> edges;
vector<vector<pair<int, int>>> adjtree;

void load() {
	cin >> n >> m;
	adj.resize(n);
	for (int i = 0; i < m; ++i) {
		int u, v;
		cin >> u >> v;
		--u; --v;
		edges.eb(u, v);
		adj[u].eb(v, i);
		adj[v].eb(u, i);
	}
	vp.resize(n);
	adjtree.resize(n);
	cin >> p;
	for (int i = 0; i < p; ++i) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		if (a == b) continue;
		vp[a].insert({i, 0});
		vp[b].insert({i, 1});
	}
}

int dfsnum[N], dfsmin[N];
int cnt = 0;

void dfsspan(int ver, int pi) {
	dfsnum[ver] = dfsmin[ver] = cnt++;
	for (auto [u, ind] : adj[ver]) {
		if (ind == pi) continue;
		if (dfsnum[u] != -1) {
			dfsmin[ver] = min(dfsmin[ver], dfsmin[u]);
		} else {
			dfsspan(u, ind);
			dfsmin[ver] = min(dfsmin[ver], dfsmin[u]);
			adjtree[ver].eb(u, dfsmin[u] > dfsnum[ver] ? ind : -1);
			adjtree[u].eb(ver, dfsmin[u] > dfsnum[ver] ? ind : -1);
		}
	}
}

string ans;

bool bio[N];

set<pair<int, int>> dfs(int ver, int par) {
	bio[ver] = true;
	set<pair<int, int>> cur = vp[ver];
	for (auto [u, t] : adjtree[ver]) {
		if (u == par) continue;
		auto tmp = dfs(u, ver);
		if (t != -1 && !tmp.empty()) {
			if (tmp.begin()->S ^ (edges[t] == pair{ver, u})) {
				ans[t] = 'L';
			} else {
				ans[t] = 'R';
			}
		}
		if (size(cur) < size(tmp)) cur.swap(tmp);
		for (auto [x, y] : tmp) {
			auto it = cur.find({x, !y});
			if (it != cur.end()) {
				cur.erase(it);
			} else {
				cur.insert({x, y});
			}
		}
		
	}
	return cur;
}

void solve() {
	memset(dfsnum, -1, sizeof dfsnum);
	for (int i = 0; i < n; ++i) {
		if (dfsnum[i] == -1) dfsspan(i, -1);
	}
	ans = string(m, 'B');
	for (int i = 0; i < n; ++i) {
		if (!bio[i]) {
			dfs(i, -1);
		}
	}
	cout << ans << '\n';
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	load();
	solve();

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 51 ms 10212 KB Output is correct
12 Correct 61 ms 13452 KB Output is correct
13 Correct 55 ms 17444 KB Output is correct
14 Correct 71 ms 21780 KB Output is correct
15 Correct 80 ms 22720 KB Output is correct
16 Correct 92 ms 20124 KB Output is correct
17 Correct 85 ms 23624 KB Output is correct
18 Correct 77 ms 20136 KB Output is correct
19 Correct 71 ms 26124 KB Output is correct
20 Correct 47 ms 15064 KB Output is correct
21 Correct 63 ms 14528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 724 KB Output is correct
2 Correct 1 ms 724 KB Output is correct
3 Correct 1 ms 852 KB Output is correct
4 Correct 1 ms 852 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 852 KB Output is correct
7 Correct 1 ms 980 KB Output is correct
8 Correct 1 ms 852 KB Output is correct
9 Correct 1 ms 852 KB Output is correct
10 Correct 1 ms 852 KB Output is correct
11 Correct 51 ms 10212 KB Output is correct
12 Correct 61 ms 13452 KB Output is correct
13 Correct 55 ms 17444 KB Output is correct
14 Correct 71 ms 21780 KB Output is correct
15 Correct 80 ms 22720 KB Output is correct
16 Correct 92 ms 20124 KB Output is correct
17 Correct 85 ms 23624 KB Output is correct
18 Correct 77 ms 20136 KB Output is correct
19 Correct 71 ms 26124 KB Output is correct
20 Correct 47 ms 15064 KB Output is correct
21 Correct 63 ms 14528 KB Output is correct
22 Correct 305 ms 42640 KB Output is correct
23 Correct 373 ms 38896 KB Output is correct
24 Correct 364 ms 37532 KB Output is correct
25 Correct 259 ms 49600 KB Output is correct
26 Correct 301 ms 41224 KB Output is correct
27 Correct 322 ms 38208 KB Output is correct
28 Correct 178 ms 23264 KB Output is correct
29 Correct 240 ms 32972 KB Output is correct
30 Correct 258 ms 32932 KB Output is correct
31 Correct 273 ms 31600 KB Output is correct
32 Correct 251 ms 40168 KB Output is correct