답안 #954592

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954592 2024-03-28T07:52:44 Z mocha One-Way Streets (CEOI17_oneway) C++14
0 / 100
3 ms 14936 KB
#include <bits/stdc++.h>
using namespace std;
const int mx = 2e5+5;

int n, m, q;
vector<int> g[mx];
int dfn[mx], low[mx];
int ans[mx];
int pe[mx];
int t;
bool vis[mx], vise[mx];
vector<int> ng[mx];
int a[mx];
int dep[mx];

struct Edge {
	int u, v;
	int id;
} e[mx];

void dfs1(int x, int peg, int d) {
	low[x] = dfn[x] = ++t;
	pe[x] = peg;
	vis[x] = 1;
	dep[x] = d;
	for (int i:g[x]) {
		if (vise[i]) continue;
		vise[i] = 1;
		auto [u, v, id] = e[i];
		if (u != x) swap(u, v);
		if (!vis[v]) {
			ng[u].push_back(v);
			ng[v].push_back(u);
			dfs1(v, i, d+1);
			low[u] = min(low[u], low[v]);
		} else {
			low[u] = min(low[u], dfn[v]);
		}
	}	
	if (low[x] != dfn[x]) {
		ans[peg] = 3;
	}
}

void dfs2(int x, int p) {
	for (int i:ng[x]) {
		if (i == p) continue;
		dfs2(i, x);
		a[x] += a[i];
	}
	if (ans[pe[x]] == 3) return;
	auto [u, v, id] = e[pe[x]];
	if (a[x] > 0) {
		if (dep[u] > dep[v]) {
			ans[id] = 1;
		} else {
			ans[id] = 2;
		}
	} else if (a[x] < 0) {
		if (dep[u] < dep[v]) {
			ans[id] = 1;
		} else {
			ans[id] = 2;
		}
	}
}

int main() {
	cin.tie(0);ios::sync_with_stdio(0);

	cin >> n >> m;
	for (int i=1;i<=m;i++) {
		int u, v;
		cin >> u >> v;
		g[u].push_back(i);
		g[v].push_back(i);
		e[i] = {u, v, i};
	}
	dfs1(1, 0, 1);
	cin >> q;
	while (q--) {
		int u, v;
		cin >> u >> v;
		a[u]++;
		a[v]--;
	}
	dfs2(1, 0);
	for (int i=1;i<=m;i++) {
		if (ans[i] == 3 or ans[i] == 0) {
			cout << 'B';
		} else if (ans[i] == 1) {
			cout << 'R';
		} else {
			cout << 'L';
		}
	}
	cout << "\n";
}

Compilation message

oneway.cpp: In function 'void dfs1(int, int, int)':
oneway.cpp:29:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   29 |   auto [u, v, id] = e[i];
      |        ^
oneway.cpp: In function 'void dfs2(int, int)':
oneway.cpp:52:7: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |  auto [u, v, id] = e[pe[x]];
      |       ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -