Submission #303086

# Submission time Handle Problem Language Result Execution time Memory
303086 2020-09-19T21:27:24 Z Kenzo_1114 One-Way Streets (CEOI17_oneway) C++17
0 / 100
3 ms 4992 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 100010;

int n, m, p, depth[MAXN], low[MAXN], id[MAXN], par[MAXN];
vector<int> graph[MAXN], edge[MAXN];
bool bridge[MAXN], marc[MAXN];
char ans[MAXN];

void dfs(int v, int p)
{
	par[v] = p;
	depth[v] = (v == p) ? 0 : depth[p] + 1;
	low[v] = depth[v];

	bool first = false;
	for(int i = 0; i < graph[v].size(); i++)
	{
		int u = graph[v][i];
		int ed = edge[v][i];

		id[u] = ed;
		
		if(low[u] != -1)
		{	
			if((u == p && first) || u != p)		low[v] = min(low[v], depth[u]);
			if(u == p)	first = true;
			continue;
		}

		dfs(u, v);
		low[v] = min(low[v], low[u]);

		if(depth[v] < low[u])	bridge[ed / 2] = true;
	}
}

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

	for(int i = 1; i <= n; i++)	low[i] = -1;

	for(int i = 0, u, v; i < m; i++)
	{
		scanf("%d %d", &u, &v);
		graph[u].push_back(v);
		graph[v].push_back(u);
		edge[u].push_back(2 * i);
		edge[v].push_back(2 * i + 1);
	}

	dfs(1, 1);

	scanf("%d", &p);

	for(int i = 0, x, y; i < p; i++)
	{
		scanf("%d %d", &x, &y);

		while(!marc[x] && par[x] != x)
		{
			if(bridge[id[x] / 2])	ans[id[x] / 2] = (id[x] % 2) ? 'R' : 'L';
			marc[x] = true;
			x = par[x];
		}

		while(!marc[y] && par[y] != y)
		{
			if(bridge[id[y] / 2])	ans[id[y] / 2] = (id[y] % 2) ? 'L' : 'R';
			marc[y] = true;
			y = par[y];
		}
	}

	for(int i = 0; i < m; i++)
		printf("%c", (ans[i] == 'L' || ans[i] == 'R') ? ans[i] : 'B');
	printf("\n");
}

/*

5 6
1 2
1 2
4 3
2 3
1 3
5 1
2
4 5
1 3

*/

Compilation message

oneway.cpp: In function 'void dfs(int, int)':
oneway.cpp:17:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  for(int i = 0; i < graph[v].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~~
oneway.cpp: In function 'int main()':
oneway.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |  scanf("%d %d", &n, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:46:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   46 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
oneway.cpp:55:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   55 |  scanf("%d", &p);
      |  ~~~~~^~~~~~~~~~
oneway.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |   scanf("%d %d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 4992 KB Output isn't correct
2 Halted 0 ms 0 KB -