Submission #161599

# Submission time Handle Problem Language Result Execution time Memory
161599 2019-11-03T08:36:02 Z amoo_safar Mousetrap (CEOI17_mousetrap) C++14
0 / 100
99 ms 28508 KB
#include <bits/stdc++.h>
 
#define pb push_back
#define F first
#define S second
 
using namespace std;
 
typedef long long ll;
typedef string str;
 
const ll Mod = 1e9 + 7;
const int Maxn = 2e5 + 100;

vector<ll> G[Maxn];
ll dp[Maxn];
ll t, m;
bool DFS(ll u, ll p){
	bool res = (u == m);
	ll cnt = 0;
	ll mx = 0;
	ll mx2 = 0;
	for(auto adj : G[u]){
		if(adj == p) continue;
		res |= DFS(adj, u);
		cnt ++;
		if(dp[adj] > mx){
			mx2 = mx;
			mx = dp[adj];
		} else mx2 = max(mx2, dp[adj]);
	}
	dp[u] = cnt + mx2;
	return res;
}
int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll n;
	cin >> n >> t >> m;
	ll u, v;
	for(int i = 1; i < n; i++){
		cin >> u >> v;
		G[u].pb(v);
		G[v].pb(u);
	}
	DFS(t, -1);
	cout << dp[m] << '\n';
	return 0;
}
/*
5 1 2
1 2
2 3
2 4
3 5

*/
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 99 ms 28508 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 5012 KB Output isn't correct
2 Halted 0 ms 0 KB -