Submission #51194

# Submission time Handle Problem Language Result Execution time Memory
51194 2018-06-17T07:54:08 Z adamczh1 One-Way Streets (CEOI17_oneway) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 1e5 + 5;

int n, m, p;
vector<int> adj[MAXN];
int a[MAXN], b[MAXN];
int x[MAXN], y[MAXN];

int Time;
int dfn[MAXN], low[MAXN];
map<pair<int, int>, bool> bridge;

void dfs(int cur, int p = -1) {
	dfn[cur] = low[cur] = ++Time;
	for (int v : adj[cur]) {
		if (!dfn[v]) {
			dfs(v, cur);
			low[cur] = min(low[cur], low[v]);
			if (low[v] > dfn[cur] && cnt[make_pair(cur, v)] == 1) {
				bridge[make_pair(cur, v)] = bridge[make_pair(v, cur)] = true;
			}
		} else if (dfn[v] < dfn[cur]) {
			low[cur] = min(low[cur], dfn[v]);
		}
	}
}

bitset<MAXN> vis;
int n_blocks;
int block[MAXN];

void dfs2(int cur, int p = -1) {
	vis[cur] = 1;
	if (p != -1) {
		block[cur] = block[p];
	}
	for (int v : adj[cur]) if (v != p) {
		if (!vis[v] && !bridge[make_pair(cur, v)]) {
			dfs2(v, cur);
		}
	}
}

set<int> tadj[MAXN];

int pre[MAXN];
map<pair<int, int>, char> mp;

int dfs3(int cur, int p = -1) {
	vis[cur] = 1;
	int val = pre[cur];
	for (int v : tadj[cur]) if (v != p) {
		val += dfs3(v, cur);
	}
	pair<int, int> pi = make_pair(p, cur);
	pair<int, int> rv = make_pair(cur, p);
	if (val < 0) {
		mp[pi] = 'L';
		mp[rv] = 'R';
	} else if (val > 0) {
		mp[pi] = 'R';
		mp[rv] = 'L';
	} else {
		mp[pi] = mp[rv] = 'B';
	}
	return val;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> a[i] >> b[i];
		adj[a[i]].push_back(b[i]);
		adj[b[i]].push_back(a[i]);
		cnt[make_pair(a[i], b[i])]++;
		cnt[make_pair(b[i], a[i])]++;
	}
	cin >> p;
	for (int i = 1; i <= p; i++) {
		cin >> x[i] >> y[i];
	}
	for (int i = 1; i <= n; i++) {
		if (!dfn[i]) {
			dfs(i);
		}
	}
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			block[i] = ++n_blocks;
			dfs2(i);
		}
	}
	for (int i = 1; i <= m; i++) {
		int A = block[a[i]];
		int B = block[b[i]];
		if (A != B) { // bridge
			tadj[A].insert(B);
			tadj[B].insert(A);
		}
	}
	for (int i = 1; i <= p; i++) {
		int u = block[x[i]];
		int v = block[y[i]];
		if (u == v) {
			continue;
		}
		pre[u]--;
		pre[v]++;
	}
	vis.reset();
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			dfs3(i);
		}
	}
	for (int i = 1; i <= m; i++) {
		int u = block[a[i]];
		int v = block[b[i]];
		if (u == v) {
			cout << 'B';
		} else {
			cout << mp[make_pair(u, v)];
		}
	}
	cout << endl;
	return 0;
}

Compilation message

oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:21:29: error: 'cnt' was not declared in this scope
    if (low[v] > dfn[cur] && cnt[make_pair(cur, v)] == 1) {
                             ^~~
oneway.cpp:21:29: note: suggested alternative: 'int'
    if (low[v] > dfn[cur] && cnt[make_pair(cur, v)] == 1) {
                             ^~~
                             int
oneway.cpp: In function 'int main()':
oneway.cpp:79:3: error: 'cnt' was not declared in this scope
   cnt[make_pair(a[i], b[i])]++;
   ^~~
oneway.cpp:79:3: note: suggested alternative: 'int'
   cnt[make_pair(a[i], b[i])]++;
   ^~~
   int