답안 #570038

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570038 2022-05-28T13:22:56 Z jesus_coconut One-Way Streets (CEOI17_oneway) C++17
0 / 100
1 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);
		}
	}
}

string ans;

set<pair<int, int>> dfs(int ver) {
	set<pair<int, int>> cur = vp[ver];
	for (auto [u, t] : adjtree[ver]) {
		auto tmp = dfs(u);
		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);
	cout << ans << '\n';
}

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

	load();
	solve();

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