Submission #303057

# Submission time Handle Problem Language Result Execution time Memory
303057 2020-09-19T20:17:22 Z Kenzo_1114 Mousetrap (CEOI17_mousetrap) C++17
25 / 100
926 ms 73592 KB
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1000010;

int n, t, m, dp[MAXN];
vector<int> graph[MAXN];

void dfs(int v, int p)
{	
	int mx[2] = {-1, -1};
	for(int i = 0; i < graph[v].size(); i++)
	{
		int u = graph[v][i];
		if(u == p)	continue;

		dfs(u, v);
		if(dp[u] >= mx[0])	mx[1] = mx[0], mx[0] = dp[u];
		else if(dp[u] > mx[1])	mx[1] = dp[u];
	}

	dp[v] = ((int) graph[v].size() == 2) ? 1 : mx[1] + graph[v].size() - 1;
	if((int) graph[v].size() == 1)	dp[v] = 0;
}

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

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

	if(t == m || (int) graph[m].size() == 0)
	{	printf("0\n"); return 0;	}

	dfs(t, t);

//	for(int i = 1; i <= n; i++)	printf("dp[%d] = %d\n", i, dp[i]);

	printf("%d\n", dp[m]);
}

Compilation message

mousetrap.cpp: In function 'void dfs(int, int)':
mousetrap.cpp:11:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |  for(int i = 0; i < graph[v].size(); i++)
      |                 ~~^~~~~~~~~~~~~~~~~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:27:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   27 |  scanf("%d %d %d", &n, &t, &m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |   scanf("%d %d", &u, &v);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 419 ms 72440 KB Output is correct
2 Correct 382 ms 67576 KB Output is correct
3 Correct 926 ms 73592 KB Output is correct
4 Correct 448 ms 48504 KB Output is correct
5 Correct 915 ms 73436 KB Output is correct
6 Correct 898 ms 73464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 23808 KB Output isn't correct
2 Halted 0 ms 0 KB -