답안 #128575

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128575 2019-07-11T07:02:04 Z faustaadp One-Way Streets (CEOI17_oneway) C++17
60 / 100
3000 ms 42616 KB
#include<bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
ll n,m,p,i,x[101010],y[101010],X[101010],Y[101010],j,te,JK;
vector<ll> v[101010],w[101010],V[101010],isi[101010],W[101010];
ll b[101010];
ll nm[101010];
ll Z[101010];
ll br[101010];
ll wk[101010];
ll mi[101010];
string s;
pair<ll,ll> P[101010];
void dfs(ll aa,ll bb)
{
	te++;
	wk[aa]=te;
	mi[aa]=te;
	b[aa]=1;
	ll ii;
	for(ii=0;ii<v[aa].size();ii++)
	{
		if(abs(w[aa][ii])==bb)continue;
		if(b[v[aa][ii]]==0)
		{
			dfs(v[aa][ii],abs(w[aa][ii]));
			mi[aa]=min(mi[aa],mi[v[aa][ii]]);
			if(wk[aa]<mi[v[aa][ii]])
			{
				br[abs(w[aa][ii])]=1;
				//cout<<aa<<" "<<v[aa][ii]<<"\n";
			}
		}
		else
		{
			mi[aa]=min(mi[aa],wk[v[aa][ii]]);
		}
	}
}
void dfs2(ll aa)
{
	b[aa]=1;
	nm[aa]=JK;
	isi[JK].pb(aa);
	ll ii;
	for(ii=0;ii<v[aa].size();ii++)
	{
		if(br[abs(w[aa][ii])])continue;
		if(b[v[aa][ii]])continue;
		dfs2(v[aa][ii]);
	}
}
void dfs3(ll aa,ll bb)
{
	b[aa]=1;
	ll ii;
	for(ii=0;ii<V[aa].size();ii++)
	{
		if(b[V[aa][ii]])continue;
		if(bb)
		{
			if((w[aa][ii]*bb)>0LL)
				s[abs(w[aa][ii])]='R';
			else
				s[abs(w[aa][ii])]='L';
		}
		dfs3(V[aa][ii],bb+Z[V[aa][ii]]);
	}
}
void dfs4(ll aa,ll bb)
{
	ll ii;
	for(ii=0;ii<V[aa].size();ii++)
		if(V[aa][ii]!=bb)
		{
			P[V[aa][ii]]=mp(aa,W[aa][ii]);
			dfs4(V[aa][ii],aa);
		}
}
int main()
{
	//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>m;
	for(i=1;i<=m;i++)
	{
		cin>>x[i]>>y[i];
		v[x[i]].pb(y[i]);
		w[x[i]].pb(i);
		v[y[i]].pb(x[i]);
		w[y[i]].pb(-i);
		s+="B";
	}
	cin>>p;
	for(i=1;i<=p;i++)cin>>X[i]>>Y[i];
	for(i=1;i<=n;i++)
	{
		if(!b[i])
			dfs(i,i);
	}
	memset(b,0,sizeof(b));
	for(i=1;i<=n;i++)
		if(!b[i])
		{
			JK++;
			dfs2(i);
		}
	//return 0;
	for(i=1;i<=m;i++)
		if(br[i])
		{
		//	cout<<nm[x[i]]<<" "<<nm[y[i]]<<"_\n";
			V[nm[x[i]]].pb(nm[y[i]]);
			W[nm[x[i]]].pb(i);
			V[nm[y[i]]].pb(nm[x[i]]);
			W[nm[y[i]]].pb(-i);
		}
	for(i=1;i<=p;i++)
	{
		dfs4(nm[X[i]],nm[X[i]]);
		P[nm[X[i]]]=mp(-1,-1);
		ll tem=nm[Y[i]];
		while(tem!=nm[X[i]])
		{
			//cout<<abs(P[tem].se)<<"_\n";
			if(P[tem].se<0)
				s[abs(P[tem].se)-1]='L';
			else
				s[abs(P[tem].se)-1]='R';
			tem=P[tem].fi;
			//cout<<tem<<"\n";
			//break;	
		}
		//cout<<nm[X[i]]<<" "<<nm[Y[i]]<<"\n";
		//Z[nm[X[i]]]++;
		//Z[nm[Y[i]]]--;
	}
	cout<<s<<"\n";
	//return 0;
	memset(b,0,sizeof(b));
	for(i=1;i<=JK;i++)
	{
		if(!b[i])
		{
			dfs3(i,Z[i]);
		}
	}
}

Compilation message

oneway.cpp: In function 'void dfs(ll, ll)':
oneway.cpp:25:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ii=0;ii<v[aa].size();ii++)
           ~~^~~~~~~~~~~~~
oneway.cpp: In function 'void dfs2(ll)':
oneway.cpp:50:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ii=0;ii<v[aa].size();ii++)
           ~~^~~~~~~~~~~~~
oneway.cpp: In function 'void dfs3(ll, ll)':
oneway.cpp:61:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ii=0;ii<V[aa].size();ii++)
           ~~^~~~~~~~~~~~~
oneway.cpp: In function 'void dfs4(ll, ll)':
oneway.cpp:77:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(ii=0;ii<V[aa].size();ii++)
           ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 13048 KB Output is correct
2 Correct 13 ms 13048 KB Output is correct
3 Correct 14 ms 13180 KB Output is correct
4 Correct 15 ms 13304 KB Output is correct
5 Correct 17 ms 13304 KB Output is correct
6 Correct 14 ms 13048 KB Output is correct
7 Correct 18 ms 13304 KB Output is correct
8 Correct 17 ms 13304 KB Output is correct
9 Correct 15 ms 13176 KB Output is correct
10 Correct 15 ms 13176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 13048 KB Output is correct
2 Correct 13 ms 13048 KB Output is correct
3 Correct 14 ms 13180 KB Output is correct
4 Correct 15 ms 13304 KB Output is correct
5 Correct 17 ms 13304 KB Output is correct
6 Correct 14 ms 13048 KB Output is correct
7 Correct 18 ms 13304 KB Output is correct
8 Correct 17 ms 13304 KB Output is correct
9 Correct 15 ms 13176 KB Output is correct
10 Correct 15 ms 13176 KB Output is correct
11 Correct 173 ms 22392 KB Output is correct
12 Correct 186 ms 24796 KB Output is correct
13 Correct 225 ms 26528 KB Output is correct
14 Correct 299 ms 30168 KB Output is correct
15 Correct 356 ms 31864 KB Output is correct
16 Correct 337 ms 38780 KB Output is correct
17 Correct 1324 ms 39800 KB Output is correct
18 Correct 1224 ms 38776 KB Output is correct
19 Correct 1171 ms 40312 KB Output is correct
20 Correct 186 ms 24208 KB Output is correct
21 Correct 177 ms 24824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 13048 KB Output is correct
2 Correct 13 ms 13048 KB Output is correct
3 Correct 14 ms 13180 KB Output is correct
4 Correct 15 ms 13304 KB Output is correct
5 Correct 17 ms 13304 KB Output is correct
6 Correct 14 ms 13048 KB Output is correct
7 Correct 18 ms 13304 KB Output is correct
8 Correct 17 ms 13304 KB Output is correct
9 Correct 15 ms 13176 KB Output is correct
10 Correct 15 ms 13176 KB Output is correct
11 Correct 173 ms 22392 KB Output is correct
12 Correct 186 ms 24796 KB Output is correct
13 Correct 225 ms 26528 KB Output is correct
14 Correct 299 ms 30168 KB Output is correct
15 Correct 356 ms 31864 KB Output is correct
16 Correct 337 ms 38780 KB Output is correct
17 Correct 1324 ms 39800 KB Output is correct
18 Correct 1224 ms 38776 KB Output is correct
19 Correct 1171 ms 40312 KB Output is correct
20 Correct 186 ms 24208 KB Output is correct
21 Correct 177 ms 24824 KB Output is correct
22 Execution timed out 3037 ms 42616 KB Time limit exceeded
23 Halted 0 ms 0 KB -