답안 #237314

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237314 2020-06-05T21:25:38 Z keta_tsimakuridze One-Way Streets (CEOI17_oneway) C++14
0 / 100
10 ms 9728 KB
#include<bits/stdc++.h>
using namespace std;
int n,m,k,u,v,mn[200005],ind[200005],fix[200005],bridge[200005],F[200005],sum[200005],timer,tmin[200005],q;
char ans[200005];
vector<pair<int,pair<int,int> > >V[200005],B[200005];
void dfs(int u,int p){
	fix[u]=1;
	timer++; 
	tmin[u]=mn[u]=timer;
	for(int i=0;i<V[u].size();i++){
		int v=V[u][i].first;
		if(v==p) continue;
		if(fix[v]==0){
			dfs(v,u);
			mn[u]=min(mn[u],mn[v]);
			if(mn[v]>tmin[u]){
				bridge[V[u][i].second.first]=1;
				F[v]=1;
				F[u]=1;
				
				
			}
		}
		else mn[u]=min(mn[u],tmin[v]);
			
	}
//	cout<<u<<"++"<<mn[u]<<endl;
	
}
void dfs1(int u,int p){
	fix[u]=2; 
	ind[u]=p;
	for(int i=0;i<V[u].size();i++){
		
		  if(bridge[V[u][i].second.first]!=0 &&fix[V[u][i].first]!=2){
			int v=V[u][i].first;
			B[v].push_back({p,{V[u][i].second.first,V[u][i].second.second}});
				B[p].push_back({v,{V[u][i].second.first,1-V[u][i].second.second}});
		}
		if(fix[V[u][i].first]!=2 && bridge[V[u][i].second.first]==0){
			dfs1(V[u][i].first,p);
		}
	
	}
}
void dfs2(int u,int p){
	fix[u]=3; 
	for(int i=0;i<B[u].size();i++){
		
		int v=B[u][i].first;
		if(v!=p ){ 
			dfs2(v,u); sum[u]+=sum[v];
			
			if(sum[v]>0){  //cout<<v<<endl;
				if(B[u][i].second.second==1){
					ans[B[u][i].second.first]='R';
				}
				else ans[B[u][i].second.first]='L';
			}
			if(sum[v]<0){
				if(B[u][i].second.second==1){
					ans[B[u][i].second.first]='L';
				}
				else ans[B[u][i].second.first]='R';
				
			}
		}
	} 
}
int main(){
	cin>>n>>m;
	for(k=1;k<=m;k++){
		cin>>u>>v;
		V[u].push_back({v,{k,1}});
		V[v].push_back({u,{k,0}});
		ans[k]='B';
	}
	
	
	
	for(k=1;k<=n;k++)
	if(!fix[k])
	dfs(k,0);
	
	for(k=1;k<=n;k++){
		if(F[k] && fix[k]!=2)dfs1(k,k);
    }
	cin>>q;
	while(q--){
		cin>>u>>v;
		sum[ind[u]]++; sum[ind[v]]--;
	}
	for(k=1;k<=n;k++){
		if(ind[k]!=k){
			for(int j=0;j<B[k].size();j++){
				B[ind[k]].push_back(B[k][j]);
			}
		}
	}
	for(k=1;k<=n;k++){
	if(fix[ind[k]]!=3 ){
	dfs2(ind[k],0);}}
	for(k=1;k<=m;k++){
		cout<<ans[k];
	}
}

Compilation message

oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:10:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
oneway.cpp: In function 'void dfs1(int, int)':
oneway.cpp:33:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<V[u].size();i++){
              ~^~~~~~~~~~~~
oneway.cpp: In function 'void dfs2(int, int)':
oneway.cpp:48:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<B[u].size();i++){
              ~^~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:95:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for(int j=0;j<B[k].size();j++){
                ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Incorrect 10 ms 9728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Incorrect 10 ms 9728 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Incorrect 10 ms 9728 KB Output isn't correct
3 Halted 0 ms 0 KB -