Submission #701131

# Submission time Handle Problem Language Result Execution time Memory
701131 2023-02-20T07:20:50 Z Darren0724 One-Way Streets (CEOI17_oneway) C++17
100 / 100
86 ms 17020 KB
#include <bits/stdc++.h>
using namespace std;

const int mxN=1e5;
int n, m, k, a[mxN], b[mxN], ab[mxN], d[mxN], s[mxN], p[mxN], r[mxN], dt=1, tin[mxN], low[mxN];
bool bg[mxN];
vector<int> adj[mxN];

int find(int x) {
	return x==p[x]?x:(p[x]=find(p[x]));
}

inline void join(int x, int y) {
	if((x=find(x))==(y=find(y)))
		return;
	if(r[x]<r[y])
		p[x]=y;
	else
		p[y]=x;
	if(r[x]==r[y])
		++r[x];
}

void dfs1(int u, int p) {
	tin[u]=low[u]=dt++;
	for(int e : adj[u]) {
		int v=u^ab[e];
		if(!tin[v]) {
			dfs1(v, e);
			low[u]=min(low[v], low[u]);
			if(low[v]>tin[u])
				bg[e]=1;
		} else if(e!=p)
			low[u]=min(tin[v], low[u]);
	}
}

void dfs2(int u, int p) {
	for(int e : adj[u]) {
		int v=u^ab[e];
		if(v==p)
			continue;
		d[v]=d[u]+1;
		dfs2(v, u);
		s[u]+=s[v];
	}
}

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

	cin >> n >> m;
	for(int i=0; i<n; ++i)
		p[i]=i;
	for(int i=0; i<m; ++i) {
		cin >> a[i] >> b[i], --a[i], --b[i];
		ab[i]=a[i]^b[i];
		adj[a[i]].push_back(i);
		adj[b[i]].push_back(i);
	}
	for(int i=0; i<n; ++i)
		if(!tin[i])
			dfs1(i, -1);
	for(int i=0; i<m; ++i)
		if(!bg[i])
			join(a[i], b[i]);
	for(int i=0; i<n; ++i)
		adj[i].clear();
	for(int i=0; i<m; ++i) {
        a[i]=find(a[i]);
		b[i]=find(b[i]);
		if(!bg[i])
			continue;
		ab[i]=a[i]^b[i];
		adj[a[i]].push_back(i);
		adj[b[i]].push_back(i);
	}
	cin >> k;
	while(k--) {
		int x, y;
		cin >> x >> y, --x, --y;
		++s[find(x)], --s[find(y)];
	}
	for(int i=0; i<n; ++i) {
		if(p[i]==i&&!d[i]) {
			d[i]=1;
			dfs2(i, -1);
		}
	}
	for(int i=0; i<m; ++i) {
		if(!bg[i]) {
            assert(a[i]==b[i]);
			cout << 'B';
			continue;
		}
        assert(abs(d[a[i]]-d[b[i]])==1);
		int u=d[a[i]]>d[b[i]]?a[i]:b[i];
		cout << (s[u]?((s[u]>0)==(u==a[i])?'R':'L'):'B');
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2708 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2708 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 32 ms 8304 KB Output is correct
12 Correct 36 ms 9676 KB Output is correct
13 Correct 44 ms 11204 KB Output is correct
14 Correct 53 ms 12412 KB Output is correct
15 Correct 66 ms 12680 KB Output is correct
16 Correct 57 ms 10272 KB Output is correct
17 Correct 60 ms 12220 KB Output is correct
18 Correct 77 ms 10324 KB Output is correct
19 Correct 48 ms 13656 KB Output is correct
20 Correct 36 ms 9112 KB Output is correct
21 Correct 35 ms 9432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2772 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2708 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2772 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 3 ms 2772 KB Output is correct
11 Correct 32 ms 8304 KB Output is correct
12 Correct 36 ms 9676 KB Output is correct
13 Correct 44 ms 11204 KB Output is correct
14 Correct 53 ms 12412 KB Output is correct
15 Correct 66 ms 12680 KB Output is correct
16 Correct 57 ms 10272 KB Output is correct
17 Correct 60 ms 12220 KB Output is correct
18 Correct 77 ms 10324 KB Output is correct
19 Correct 48 ms 13656 KB Output is correct
20 Correct 36 ms 9112 KB Output is correct
21 Correct 35 ms 9432 KB Output is correct
22 Correct 71 ms 13404 KB Output is correct
23 Correct 67 ms 11428 KB Output is correct
24 Correct 86 ms 11524 KB Output is correct
25 Correct 63 ms 17020 KB Output is correct
26 Correct 63 ms 12864 KB Output is correct
27 Correct 70 ms 11532 KB Output is correct
28 Correct 28 ms 6220 KB Output is correct
29 Correct 51 ms 9804 KB Output is correct
30 Correct 51 ms 10432 KB Output is correct
31 Correct 52 ms 10240 KB Output is correct
32 Correct 62 ms 13516 KB Output is correct