Submission #878722

# Submission time Handle Problem Language Result Execution time Memory
878722 2023-11-25T06:25:59 Z Jawad_Akbar_JJ Mousetrap (CEOI17_mousetrap) C++14
0 / 100
107 ms 22812 KB
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
const int N = 2e5  + 10;
vector<int> nei[N];
int par[N];
int Mx1[N];
int Mx2[N];

void Dfs(int u,int p = -1){
	par[u] = p;
	
	for (int i : nei[u]){
		if (i==p)
			continue;
		Dfs(i,u);
		int mx = Mx2[i] + 1;
		if (mx>Mx1[u]){
			Mx2[u] = Mx1[u];
			Mx1[u] = mx;
		}
		else
			Mx2[u] = max(Mx2[u],mx);
	}
}

signed main(){
	int n,t,m;
	cin>>n>>t>>m;
	
	for (int i=2;i<=n;i++){
		int u,v;
		cin>>u>>v;
		nei[u].push_back(v);
		nei[v].push_back(u);
	}
	
	Dfs(t);
	
	// for (int i=1;i<=n;i++)
		// cout<<Mx1[i]<<" "<<Mx2[i]<<endl;
	int mx = 0;
	int Mx = 1;
	for (int i : nei[m]){
		if (i==t)
			continue;
		if (Mx1[i] + 1>Mx){
			mx = Mx;
			Mx = Mx1[i] + 1;
		}
		else
			mx = max(mx,Mx1[i] + 1);
	}
	
	int flag = true;
	int block = 0;
	for (int i : nei[m]){
		if (i==t)
			continue;
		block++;
	}
	if (Mx==0){
		cout<<0<<endl;
	}
	else if (mx == 0){
		cout<<1<<endl;
	}
	else
		cout<<block + mx - 1<<endl;
}

Compilation message

mousetrap.cpp: In function 'int main()':
mousetrap.cpp:57:6: warning: unused variable 'flag' [-Wunused-variable]
   57 |  int flag = true;
      |      ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 107 ms 22812 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 7260 KB Output isn't correct
2 Halted 0 ms 0 KB -