Submission #161600

# Submission time Handle Problem Language Result Execution time Memory
161600 2019-11-03T08:36:50 Z amoo_safar Mousetrap (CEOI17_mousetrap) C++14
25 / 100
1008 ms 82504 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 = 1e6 + 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 24 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 460 ms 81836 KB Output is correct
2 Correct 407 ms 78120 KB Output is correct
3 Correct 980 ms 82304 KB Output is correct
4 Correct 497 ms 52932 KB Output is correct
5 Correct 990 ms 82504 KB Output is correct
6 Correct 1008 ms 82364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 23928 KB Output isn't correct
2 Halted 0 ms 0 KB -