Submission #570040

# Submission time Handle Problem Language Result Execution time Memory
570040 2022-05-28T13:32:57 Z jesus_coconut One-Way Streets (CEOI17_oneway) C++17
0 / 100
0 ms 212 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 = 1005;

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;

set<pair<int, int>> dfs(int ver, int par) {
	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);
	
	dfsspan(0, -1);
	ans = string(m, 'B');
	dfs(0, -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 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -