답안 #652772

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
652772 2022-10-24T09:19:05 Z alvingogo One-Way Streets (CEOI17_oneway) C++14
100 / 100
100 ms 23152 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define AquA cin.tie(0);ios_base::sync_with_stdio(0);
#define fs first
#define sc second
#define cd complex<double>
#define p_q priority_queue
using namespace std;

vector<vector<pair<int,int> > > e;
vector<int> dfn,low;
vector<int> ans;
vector<int> vis;
vector<int> tt;
int cnt=1,cc=0;
stack<int> sk;
void dfs(int r,int f){
	dfn[r]=low[r]=cnt;
	cnt++;
	sk.push(r);
	if(f>=0){
		vis[f]=1;
	}
	for(auto h:e[r]){
		if(vis[h.sc]){
			continue;
		}
		if(dfn[h.fs]){
			low[r]=min(low[r],dfn[h.fs]);
		}
		else{
			dfs(h.fs,h.sc);
			low[r]=min(low[r],low[h.fs]);
			if(low[h.fs]>dfn[r]){
				cc++;
				int k;
				do{
					k=sk.top();
					tt[k]=cc;
					sk.pop();
				}while(k!=h.fs);
			}
		}
	}
	if(f==-1){
		cc++;
		do{
			tt[sk.top()]=cc;
			sk.pop();
		}while(sk.size());
	}
}
vector<vector<pair<int,int> > > ff;
vector<pair<int,int> > eg;
vector<int> kk;
vector<int> vvvvv;
void dfs2(int x,int y,int z){
	vvvvv[x]=1;
	for(auto h:ff[x]){
		if(h.fs!=y){
			dfs2(h.fs,x,h.sc);
			kk[x]+=kk[h.fs];
		}
	}
	if(kk[x]!=0){
		ans[z]=((kk[x]>0)^(x==eg[z].fs))?1:-1;
	}
}
int main(){
	AquA;
	int n,m;
	cin >> n >> m;
	e.resize(n);
	eg.resize(m);
	for(int i=0;i<m;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		e[a].push_back({b,i});
		e[b].push_back({a,i});
		eg[i]={a,b};
	}
	dfn.resize(n);
	low.resize(n);
	ans.resize(m);
	vis.resize(m);
	tt.resize(n);
	for(int i=0;i<n;i++){
		if(!dfn[i]){
			dfs(i,-1);
		}
	}
	ff.resize(cc+1);
	for(int i=0;i<n;i++){
		for(auto h:e[i]){
			if(tt[i]!=tt[h.fs]){
				ff[tt[i]].push_back({tt[h.fs],h.sc});
			}
		}
	}
	for(int i=0;i<m;i++){
		eg[i]={tt[eg[i].fs],tt[eg[i].sc]};
	}
	int p;
	cin >> p;
	kk.resize(cc+1);
	for(int i=0;i<p;i++){
		int a,b;
		cin >> a >> b;
		a--;
		b--;
		a=tt[a];
		b=tt[b];
		if(a==b){
			continue;
		}
		kk[a]++;
		kk[b]--;
	}
	/*
	for(int i=0;i<=cc;i++){
		cout << i << "\n";
		for(auto h:ff[i]){
			cout << h.fs << " " << h.sc << "\n";
		}
		cout << "\n";
	}
	*/	
	vvvvv.resize(cc+1);
	for(int i=1;i<=cc;i++){
		if(vvvvv[i]==0){
			dfs2(i,0,-1);
		}
	}
	for(int i=0;i<m;i++){
		if(ans[i]==0){
			cout << "B";
		}
		else if(ans[i]==1){
			cout << "L";
		}
		else if(ans[i]==-1){
			cout << "R";
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 36 ms 7652 KB Output is correct
12 Correct 41 ms 8892 KB Output is correct
13 Correct 53 ms 10604 KB Output is correct
14 Correct 59 ms 13088 KB Output is correct
15 Correct 68 ms 14064 KB Output is correct
16 Correct 76 ms 17188 KB Output is correct
17 Correct 76 ms 18576 KB Output is correct
18 Correct 85 ms 17196 KB Output is correct
19 Correct 74 ms 20056 KB Output is correct
20 Correct 43 ms 9112 KB Output is correct
21 Correct 37 ms 8656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 320 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 452 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 36 ms 7652 KB Output is correct
12 Correct 41 ms 8892 KB Output is correct
13 Correct 53 ms 10604 KB Output is correct
14 Correct 59 ms 13088 KB Output is correct
15 Correct 68 ms 14064 KB Output is correct
16 Correct 76 ms 17188 KB Output is correct
17 Correct 76 ms 18576 KB Output is correct
18 Correct 85 ms 17196 KB Output is correct
19 Correct 74 ms 20056 KB Output is correct
20 Correct 43 ms 9112 KB Output is correct
21 Correct 37 ms 8656 KB Output is correct
22 Correct 97 ms 19840 KB Output is correct
23 Correct 93 ms 18188 KB Output is correct
24 Correct 100 ms 18380 KB Output is correct
25 Correct 98 ms 23152 KB Output is correct
26 Correct 98 ms 19640 KB Output is correct
27 Correct 79 ms 18268 KB Output is correct
28 Correct 29 ms 5332 KB Output is correct
29 Correct 58 ms 9804 KB Output is correct
30 Correct 58 ms 9920 KB Output is correct
31 Correct 56 ms 10260 KB Output is correct
32 Correct 63 ms 14076 KB Output is correct