Submission #1027568

# Submission time Handle Problem Language Result Execution time Memory
1027568 2024-07-19T07:40:10 Z toan2602 One-Way Streets (CEOI17_oneway) C++14
100 / 100
93 ms 20192 KB
#include<bits/stdc++.h>

using namespace std;
int n, m, p, u, v, lead[100005], low[100005], num[100005], d = 0, cnt = 0, ans[100005], timer = 0, q, val[100005];
vector<pair<int,int>> adj[100005];
vector<pair<int,int>> adj2[100005], edge;
stack<int> s;
bool mark[100005];
void dfs(int u, int id) {
	low[u] = num[u] = ++d;
	s.push(u);
	for (pair<int, int> W: adj[u]) {
		int node = W.first;
		if(W.second == id) continue;
		if(num[node] != 0) low[u] = min(low[u], num[node]);
		else {
			dfs(node, W.second);
			low[u] = min(low[u], low[node]);
		}
	}
	if(low[u] == num[u]) {
		cnt++;
		while(s.top() != u) lead[s.top()] = cnt, s.pop();
		lead[s.top()] = cnt, s.pop();
	}
}
void cal(int u, int par) {
	for (pair<int, int> node: adj2[u]) {
		if(mark[node.first]) continue;
		mark[node.first] = true;
		cal(node.first, u);
		val[u] += val[node.first];
	}
}
void get_ans(int u, int par) {
	for (pair<int, int> node: adj2[u]) {
		if(mark[node.first]) continue;
		mark[node.first] = true;
		int x, y;
		x = u, y = node.first;
		int id = node.second;
		//cout << "QWFQWF " << x << ' ' << y  << ' ' << id << '\n';
		if(val[node.first] < 0) {
			//cout << "EDGE " << x << ' ' << y << ' ' << edge[id].first << ' ' << edge[id].second << '\n';
			if(lead[edge[id].first] == x && lead[edge[id].second] == y) ans[id+1] = 1;
			else ans[id+1] = 2;
		}
		else if(val[node.first] > 0) {
			//cout << "EDGE " << x << ' ' << y << ' ' << edge[id].first << ' ' << edge[id].second << '\n';
			if(lead[edge[id].first] == x && lead[edge[id].second] == y) ans[id+1] = 2;
			else ans[id+1] = 1;
		}
		else ans[id+1] = 0;
		get_ans(node.first, u);
	}
}
void solve() {
	cin >> n >> m;
	for (int i = 1; i <= m; i++) {
		cin >> u >> v;
		edge.push_back({u,v});
		adj[u].push_back({v,i});
		adj[v].push_back({u,i});
	}
	for (int i = 1; i <= n; i++) {
		if(num[i] == 0) dfs(i, -1);
	}
	int idx = 0;
	for (pair<int, int> i: edge) {
		if(lead[i.first] != lead[i.second]) adj2[lead[i.first]].push_back({lead[i.second], idx}), adj2[lead[i.second]].push_back({lead[i.first],idx});
		idx++;
	}
	cin >> q;
	while(q--) {
		cin >> u >> v;
		u = lead[u];
		v = lead[v];
		val[u]++;
		val[v]--;
	}
	for (int i = 1; i <= cnt; i++) if(!mark[i]) cal(i,-1);
	memset(mark, 0, sizeof(mark));
	for (int i = 1; i <= cnt; i++) if(!mark[i]) get_ans(i, -1);
	for (int i = 1; i <= m; i++) if(ans[i] == 0) cout << 'B'; else if(ans[i] == 1) cout << 'R'; else cout << 'L';
}

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	if(fopen("input.inp","r")){
		freopen("input.inp", "r", stdin);
		freopen("output.out", "w", stdout);
	}
	int t = 1;
	// cin >> t;
	while(t--) {
		solve();
	}
}

Compilation message

oneway.cpp: In function 'int main()':
oneway.cpp:90:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |   freopen("input.inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
oneway.cpp:91:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   freopen("output.out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 25 ms 11724 KB Output is correct
12 Correct 29 ms 12476 KB Output is correct
13 Correct 37 ms 13516 KB Output is correct
14 Correct 35 ms 14228 KB Output is correct
15 Correct 37 ms 14532 KB Output is correct
16 Correct 45 ms 15556 KB Output is correct
17 Correct 42 ms 16836 KB Output is correct
18 Correct 48 ms 15556 KB Output is correct
19 Correct 36 ms 18148 KB Output is correct
20 Correct 25 ms 11976 KB Output is correct
21 Correct 29 ms 11728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6748 KB Output is correct
2 Correct 1 ms 6748 KB Output is correct
3 Correct 1 ms 6748 KB Output is correct
4 Correct 1 ms 6748 KB Output is correct
5 Correct 2 ms 6748 KB Output is correct
6 Correct 2 ms 6748 KB Output is correct
7 Correct 2 ms 6748 KB Output is correct
8 Correct 1 ms 6748 KB Output is correct
9 Correct 1 ms 6748 KB Output is correct
10 Correct 1 ms 6748 KB Output is correct
11 Correct 25 ms 11724 KB Output is correct
12 Correct 29 ms 12476 KB Output is correct
13 Correct 37 ms 13516 KB Output is correct
14 Correct 35 ms 14228 KB Output is correct
15 Correct 37 ms 14532 KB Output is correct
16 Correct 45 ms 15556 KB Output is correct
17 Correct 42 ms 16836 KB Output is correct
18 Correct 48 ms 15556 KB Output is correct
19 Correct 36 ms 18148 KB Output is correct
20 Correct 25 ms 11976 KB Output is correct
21 Correct 29 ms 11728 KB Output is correct
22 Correct 51 ms 16836 KB Output is correct
23 Correct 93 ms 15304 KB Output is correct
24 Correct 57 ms 15556 KB Output is correct
25 Correct 53 ms 20192 KB Output is correct
26 Correct 84 ms 16580 KB Output is correct
27 Correct 67 ms 15268 KB Output is correct
28 Correct 25 ms 9676 KB Output is correct
29 Correct 32 ms 11672 KB Output is correct
30 Correct 33 ms 11620 KB Output is correct
31 Correct 40 ms 12084 KB Output is correct
32 Correct 43 ms 14508 KB Output is correct