답안 #171905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171905 2019-12-30T15:22:08 Z dvdg6566 One-Way Streets (CEOI17_oneway) C++14
100 / 100
310 ms 26804 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 101010

vpi V[MAXN];
int N,E,a,b;
int p[MAXN];
int W[MAXN];
stack<int> stk;
int lowlink[MAXN], bcc[MAXN], depth[MAXN];
vpi A[MAXN];
int out[MAXN];
int indextopar[MAXN];
int pp[MAXN];
vpi edges;

void dfs(int x, int w){
	depth[x] = lowlink[x] = a++;
	stk.push(x);
	for (auto i : V[x])if(i.s != w){
		if (p[i.f]){
			lowlink[x] = min(lowlink[x], lowlink[i.f]);
			continue;
		}
		p[i.f] = x;
		dfs(i.f,i.s);
		lowlink[x] = min(lowlink[x], lowlink[i.f]);
	}
	if (lowlink[x] == depth[x]){
		while(stk.top() != x){
			bcc[stk.top()] = b;
			stk.pop();
		}
		stk.pop();
		bcc[x] = b++;
	}
}

void d2(int x){
	for (auto v:A[x])if(v.f != pp[x]){
		pp[v.f] = x;
		depth[v.f] = depth[x]+1;
		indextopar[v.f] = v.s;
		d2(v.f);
	}
}

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

int main(){
	cin>>N>>E;
	for (int i=0;i<E;++i){
		cin>>a>>b;
		V[a].pb(b,i);
		V[b].pb(a,i);
		edges.pb(a,b);
	}
	a=1;b=1;
	for (int i=1;i<=N;++i)if(p[i] == 0){
		p[i] = 1;
		dfs(i,-1);
	}
	memset(out,-1,sizeof(out));
	// for (int i=1;i<=N;++i)cout<<bcc[i]<<' ';cout<<'\n';
	N = b-1;
	for (int i=0;i<SZ(edges);++i){
		a = bcc[edges[i].f];
		b = bcc[edges[i].s];
		edges[i].f = a;
		edges[i].s = b;
		if (a == b)continue;
		A[a].pb(b,i);
		A[b].pb(a,i);
		// cout<<a<<' '<<b<<' '<<i<<'\n';
	}
	memset(out,-1,sizeof(out));
	memset(depth,0,sizeof(depth));
	for (int i=1;i<=N;++i)if(depth[i] == 0){
		depth[i]=1;
		d2(i);
	}
	for (int i=1;i<=N;++i)p[i]=i;
	int Q;
	cin>>Q;
	while(Q--){
		cin>>a>>b;
		a=bcc[a];b=bcc[b];
		while (1){
			a = par(a);
			b = par(b);
			// cout<<a<<' '<<b<<'\n';
			if (a == b)break;
			if (depth[a] > depth[b]){
				int target = indextopar[a];
				// cout<<"Set "<<target<<" to "<<a<<'\n';
				out[target] = pp[a];
				// assert(pp[a] == edges[target].f || pp[a] == edges[target].s);
				p[a] = pp[a];
				a = pp[a];
			}else{
				int target = indextopar[b];
				out[target] = b;
				// assert(b == edges[target].f || b == edges[target].s);
				// cout<<"Set "<<target<<" to "<<b<<'\n';
				p[b] = pp[b];
				b = pp[b];
			}
		}
		// cout<<'\n';
	}
	// for (int i=0;i<E;++i)cout<<out[i]<<' ';
	for (int i=0;i<E;++i){
		if (out[i] == -1)cout<<"B";
		else if (edges[i].f == out[i])cout<<"L";
		else if (edges[i].s == out[i])cout<<"R";
		// else assert(0);
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5880 KB Output is correct
2 Correct 7 ms 5880 KB Output is correct
3 Correct 8 ms 6008 KB Output is correct
4 Correct 8 ms 6008 KB Output is correct
5 Correct 8 ms 6180 KB Output is correct
6 Correct 8 ms 6008 KB Output is correct
7 Correct 8 ms 6008 KB Output is correct
8 Correct 8 ms 6008 KB Output is correct
9 Correct 8 ms 6008 KB Output is correct
10 Correct 8 ms 6008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5880 KB Output is correct
2 Correct 7 ms 5880 KB Output is correct
3 Correct 8 ms 6008 KB Output is correct
4 Correct 8 ms 6008 KB Output is correct
5 Correct 8 ms 6180 KB Output is correct
6 Correct 8 ms 6008 KB Output is correct
7 Correct 8 ms 6008 KB Output is correct
8 Correct 8 ms 6008 KB Output is correct
9 Correct 8 ms 6008 KB Output is correct
10 Correct 8 ms 6008 KB Output is correct
11 Correct 141 ms 15140 KB Output is correct
12 Correct 180 ms 16064 KB Output is correct
13 Correct 168 ms 17128 KB Output is correct
14 Correct 179 ms 18020 KB Output is correct
15 Correct 238 ms 18916 KB Output is correct
16 Correct 255 ms 20664 KB Output is correct
17 Correct 185 ms 22500 KB Output is correct
18 Correct 198 ms 20692 KB Output is correct
19 Correct 183 ms 23352 KB Output is correct
20 Correct 159 ms 15616 KB Output is correct
21 Correct 146 ms 15068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 5880 KB Output is correct
2 Correct 7 ms 5880 KB Output is correct
3 Correct 8 ms 6008 KB Output is correct
4 Correct 8 ms 6008 KB Output is correct
5 Correct 8 ms 6180 KB Output is correct
6 Correct 8 ms 6008 KB Output is correct
7 Correct 8 ms 6008 KB Output is correct
8 Correct 8 ms 6008 KB Output is correct
9 Correct 8 ms 6008 KB Output is correct
10 Correct 8 ms 6008 KB Output is correct
11 Correct 141 ms 15140 KB Output is correct
12 Correct 180 ms 16064 KB Output is correct
13 Correct 168 ms 17128 KB Output is correct
14 Correct 179 ms 18020 KB Output is correct
15 Correct 238 ms 18916 KB Output is correct
16 Correct 255 ms 20664 KB Output is correct
17 Correct 185 ms 22500 KB Output is correct
18 Correct 198 ms 20692 KB Output is correct
19 Correct 183 ms 23352 KB Output is correct
20 Correct 159 ms 15616 KB Output is correct
21 Correct 146 ms 15068 KB Output is correct
22 Correct 305 ms 21840 KB Output is correct
23 Correct 307 ms 22172 KB Output is correct
24 Correct 310 ms 22116 KB Output is correct
25 Correct 295 ms 26804 KB Output is correct
26 Correct 291 ms 23380 KB Output is correct
27 Correct 309 ms 22400 KB Output is correct
28 Correct 141 ms 12772 KB Output is correct
29 Correct 253 ms 16228 KB Output is correct
30 Correct 242 ms 16340 KB Output is correct
31 Correct 249 ms 16712 KB Output is correct
32 Correct 274 ms 19844 KB Output is correct