Submission #237357

# Submission time Handle Problem Language Result Execution time Memory
237357 2020-06-06T06:13:54 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; //cout<<V[u][i].second.first<<endl;
				F[u]=1;


			}
		} else mn[u]=min(mn[u],tmin[v]);

	}

}
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) {
				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(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:16: 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:31:16: 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:46:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0; i<B[u].size(); i++) {
               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 9728 KB Output isn't correct
2 Halted 0 ms 0 KB -