답안 #878662

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878662 2023-11-25T03:59:08 Z Faisal_Saqib Mousetrap (CEOI17_mousetrap) C++17
0 / 100
799 ms 60216 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)
{
	if(x==t or (p!=-1 and ma[x].size()==1))
		return;
	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)
		{
			dp[y]++;
			if(dp[y]>mx)
			{
				mx2=mx;
				mx=dp[y];
			}
			else if(dp[y]>mx2)
			{
				mx2=dp[y];
			}
		}
	}
	dp[x]=mx2+total-1-(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;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 656 ms 58940 KB Output is correct
2 Correct 510 ms 55980 KB Output is correct
3 Correct 799 ms 60216 KB Output is correct
4 Incorrect 396 ms 43856 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 25436 KB Output isn't correct
2 Halted 0 ms 0 KB -