Submission #158578

# Submission time Handle Problem Language Result Execution time Memory
158578 2019-10-18T01:44:22 Z Lawliet One-Way Streets (CEOI17_oneway) C++17
100 / 100
186 ms 25496 KB
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 100010;

int n, m, q;
int curTime;

int ans[MAXN];
int low[MAXN];
int pre[MAXN];
int sub[MAXN];

bool marc[MAXN];

vector< int > adj[MAXN];
vector< int > indEdge[MAXN];
vector< int > direction[MAXN];

void DFSLowlink(int cur, int p)
{
	marc[ cur ] = true;
	low[ cur ] = pre[ cur ] = ++curTime;

	for(int i = 0 ; i < adj[ cur ].size() ; i++)
	{
		int viz = adj[ cur ][ i ];
		int ind = indEdge[ cur ][ i ];
		int d = direction[ cur ][ i ];

		if( marc[ viz ] )
		{
			if( ind != p ) low[ cur ] = min(low[ cur ] , pre[ viz ]);

			continue;
		}

		DFSLowlink( viz , ind );

		if( low[ viz ] > pre[ cur ] )
		{
			if( sub[ viz ] > 0 ) ans[ ind ] = d;
			if( sub[ viz ] < 0 ) ans[ ind ] = 3 - d;
		}

		sub[ cur ] += sub[ viz ];
		low[ cur ] = min(low[ cur ] , low[ viz ]);
	}
}

int main()
{
	scanf("%d %d",&n,&m);

	for(int i = 1 ; i <= m ; i++)
	{
		int U, V;
		scanf("%d %d",&U,&V);

		adj[ U ].push_back( V );
		adj[ V ].push_back( U );

		indEdge[ U ].push_back( i );
		indEdge[ V ].push_back( i );

		direction[ U ].push_back( 1 );
		direction[ V ].push_back( 2 );
	}

	scanf("%d",&q);

	for(int i = 1 ; i <= q ; i++)
	{
		int X, Y;
		scanf("%d %d",&X,&Y);

		sub[ X ]++;
		sub[ Y ]--;
	}

	for(int i = 1 ; i <= n ; i++)
		if( !marc[i] ) DFSLowlink( i , 0 );

	for(int i = 1 ; i <= m ; i++)
	{
		if(ans[ i ] == 0) printf("B");
		if(ans[ i ] == 1) printf("L");
		if(ans[ i ] == 2) printf("R");
	}
}

Compilation message

oneway.cpp: In function 'void DFSLowlink(int, int)':
oneway.cpp:26:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i = 0 ; i < adj[ cur ].size() ; i++)
                  ~~^~~~~~~~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
oneway.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&U,&V);
   ~~~~~^~~~~~~~~~~~~~~
oneway.cpp:71:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
oneway.cpp:76:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&X,&Y);
   ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7288 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7544 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Correct 8 ms 7544 KB Output is correct
8 Correct 9 ms 7544 KB Output is correct
9 Correct 9 ms 7416 KB Output is correct
10 Correct 8 ms 7416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7288 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7544 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Correct 8 ms 7544 KB Output is correct
8 Correct 9 ms 7544 KB Output is correct
9 Correct 9 ms 7416 KB Output is correct
10 Correct 8 ms 7416 KB Output is correct
11 Correct 85 ms 14436 KB Output is correct
12 Correct 95 ms 15964 KB Output is correct
13 Correct 126 ms 17784 KB Output is correct
14 Correct 138 ms 19684 KB Output is correct
15 Correct 147 ms 20096 KB Output is correct
16 Correct 150 ms 19688 KB Output is correct
17 Correct 129 ms 21504 KB Output is correct
18 Correct 147 ms 19936 KB Output is correct
19 Correct 116 ms 22508 KB Output is correct
20 Correct 95 ms 16212 KB Output is correct
21 Correct 86 ms 16288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 10 ms 7288 KB Output is correct
3 Correct 9 ms 7416 KB Output is correct
4 Correct 9 ms 7544 KB Output is correct
5 Correct 9 ms 7544 KB Output is correct
6 Correct 8 ms 7416 KB Output is correct
7 Correct 8 ms 7544 KB Output is correct
8 Correct 9 ms 7544 KB Output is correct
9 Correct 9 ms 7416 KB Output is correct
10 Correct 8 ms 7416 KB Output is correct
11 Correct 85 ms 14436 KB Output is correct
12 Correct 95 ms 15964 KB Output is correct
13 Correct 126 ms 17784 KB Output is correct
14 Correct 138 ms 19684 KB Output is correct
15 Correct 147 ms 20096 KB Output is correct
16 Correct 150 ms 19688 KB Output is correct
17 Correct 129 ms 21504 KB Output is correct
18 Correct 147 ms 19936 KB Output is correct
19 Correct 116 ms 22508 KB Output is correct
20 Correct 95 ms 16212 KB Output is correct
21 Correct 86 ms 16288 KB Output is correct
22 Correct 145 ms 22500 KB Output is correct
23 Correct 149 ms 21168 KB Output is correct
24 Correct 186 ms 21332 KB Output is correct
25 Correct 151 ms 25496 KB Output is correct
26 Correct 151 ms 22136 KB Output is correct
27 Correct 153 ms 21112 KB Output is correct
28 Correct 59 ms 11640 KB Output is correct
29 Correct 127 ms 17040 KB Output is correct
30 Correct 112 ms 17400 KB Output is correct
31 Correct 122 ms 17368 KB Output is correct
32 Correct 120 ms 20344 KB Output is correct