Submission #878673

# Submission time Handle Problem Language Result Execution time Memory
878673 2023-11-25T04:34:35 Z Faisal_Saqib Mousetrap (CEOI17_mousetrap) C++17
25 / 100
835 ms 60324 KB
#include <iostream>
#include <vector>
using namespace std;
const int N=1e6+2;
vector<int> ma[N];
int dp[N]; // dp[x] = def = what is the minimum number of step(Of Kalu ustad) return back to x,such that the subtree of x  are  the only cities you can go to
int n,t,m;
void dfs(int x,int p=-1)
{
	int total=0;
	for(auto y:ma[x])
	{
		if(y!=p)
		{
			dfs(y,x);
			total++;
		}
	}
	int mx=0;
	int mx2=0;
	for(auto y:ma[x])
	{
		if(y!=p)
		{
			if(dp[y]>mx)
			{
				mx2=mx;
				mx=dp[y];
			}
			else if(dp[y]>mx2)
			{
				mx2=dp[y];
			}
		}
	}
	dp[x]=mx2+total-(x==m);
}
int main()
{
	cin>>n>>t>>m;
	for(int i=1;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		ma[x].push_back(y);
		ma[y].push_back(x);
	}
	dfs(m);
	cout<<dp[m]<<endl;
	// for(int i=1;i<=n;i++)
	// {
	// 	cout<<"for" <<i<<' '<<dp[i]<<endl;
	// }
	return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 493 ms 59072 KB Output is correct
2 Correct 441 ms 55888 KB Output is correct
3 Correct 835 ms 60324 KB Output is correct
4 Correct 361 ms 43860 KB Output is correct
5 Correct 824 ms 60156 KB Output is correct
6 Correct 829 ms 60084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -