Submission #308796

# Submission time Handle Problem Language Result Execution time Memory
308796 2020-10-02T00:25:17 Z wmrmr Mousetrap (CEOI17_mousetrap) C++17
25 / 100
909 ms 65144 KB
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6+1;
int dp[MAX], pai[MAX];
int n,t,m;
vector<int> g[MAX];

void DFS1(int v, int p)
{
	pai[v] = p;
	int grau = g[v].size();
	int mxfirst = 0, mxsecond = 0;
	for(int i=0;i<grau;i++)
	{
		int prox = g[v][i];
		if(prox == p) continue;
		DFS1(prox,v);
		if(dp[prox] >= mxfirst)
			mxsecond = mxfirst, mxfirst = dp[prox];
		else
		{ 
			if(dp[prox] > mxsecond)
				mxsecond = dp[prox];
		}
	}
	dp[v] = grau + mxsecond - 1;
}

void DFS2(int v, int f, int ans)
{
	if(v == t) {
		printf("%d\n",ans); return; }
	if(f == 0) {
		DFS2(pai[v],v,dp[v]); return; }
	int grau = g[v].size();
	int mxfirst = 0, mxsecond = 0;
	for(int i=0;i<g[v].size();i++)
	{
		int prox = g[v][i];
		if(prox == f || prox == pai[v]) continue;
		if(dp[prox] >= mxfirst)
			mxsecond = mxfirst, mxfirst = dp[prox];
		else
		{
			if(dp[prox] > mxsecond)
				mxsecond = dp[prox];
		}
	}
	DFS2(pai[v],v,ans+grau+mxsecond-2);
}

int main()
{
	scanf("%d %d %d",&n,&t,&m);
	for(int i=1;i<n;i++)
	{
		int a,b; scanf("%d %d",&a,&b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	for(int i=0;i<g[t].size();i++)
	{
		DFS1(g[t][i],t);
	}
	DFS2(m,0,0);
}

Compilation message

mousetrap.cpp: In function 'void DFS2(int, int, int)':
mousetrap.cpp:37:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for(int i=0;i<g[v].size();i++)
      |              ~^~~~~~~~~~~~
mousetrap.cpp: In function 'int main()':
mousetrap.cpp:61:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |  for(int i=0;i<g[t].size();i++)
      |              ~^~~~~~~~~~~~
mousetrap.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   54 |  scanf("%d %d %d",&n,&t,&m);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~
mousetrap.cpp:57:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   57 |   int a,b; scanf("%d %d",&a,&b);
      |            ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Incorrect 17 ms 23808 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 418 ms 63992 KB Output is correct
2 Correct 372 ms 59896 KB Output is correct
3 Correct 909 ms 65108 KB Output is correct
4 Correct 431 ms 44920 KB Output is correct
5 Correct 909 ms 65144 KB Output is correct
6 Correct 903 ms 65012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Incorrect 17 ms 23808 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 17 ms 23808 KB Output is correct
3 Correct 17 ms 23808 KB Output is correct
4 Correct 17 ms 23808 KB Output is correct
5 Incorrect 17 ms 23808 KB Output isn't correct
6 Halted 0 ms 0 KB -