Submission #127016

# Submission time Handle Problem Language Result Execution time Memory
127016 2019-07-08T19:33:05 Z Lawliet Mousetrap (CEOI17_mousetrap) C++14
25 / 100
1047 ms 77432 KB
#include <bits/stdc++.h>

#define MAX 1000010

using namespace std;
typedef long long int lli;

int n;
int mouse, trap;
int n1, n2;

lli dp[MAX];

vector<int> grafo[MAX];

void DFS(int i, int p)
{
	if(grafo[i].size() == 1 && i != trap)
	{
		dp[i] = 0;
		return;
	}

	vector<int> aux;

	aux.push_back( 0 );

	for(int g = 0 ; g < grafo[i].size() ; g++)
	{
		int prox = grafo[i][g];

		if(prox == p) continue;

		//printf("i = %d  prox = %d\n",i,prox);

		DFS(prox , i);

		aux.push_back( dp[prox] );
	}

	sort(aux.begin() , aux.end());

	dp[i] = grafo[i].size() - 2 + aux[aux.size() - 2] + 1;

	//printf("dp(%d) = %lld\n",i,dp[i]);
}

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

	for(int g = 0 ; g < n - 1 ; g++)
	{
		scanf("%d %d",&n1,&n2);

		grafo[n1].push_back(n2);
		grafo[n2].push_back(n1);
	}

	DFS(trap , trap);

	printf("%lld\n",dp[mouse]);
}

Compilation message

mousetrap.cpp: In function 'void DFS(int, int)':
mousetrap.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int g = 0 ; g < grafo[i].size() ; g++)
                  ~~^~~~~~~~~~~~~~~~~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&trap,&mouse);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&n1,&n2);
   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 526 ms 76400 KB Output is correct
2 Correct 465 ms 71092 KB Output is correct
3 Correct 1030 ms 77364 KB Output is correct
4 Correct 572 ms 50532 KB Output is correct
5 Correct 1022 ms 77432 KB Output is correct
6 Correct 1047 ms 77432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 23 ms 23800 KB Output isn't correct
2 Halted 0 ms 0 KB -