Submission #161604

# Submission time Handle Problem Language Result Execution time Memory
161604 2019-11-03T09:00:11 Z shayan_p Mousetrap (CEOI17_mousetrap) C++14
0 / 100
399 ms 55160 KB
// Remember...

#include<bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

const int maxn=1e6+10,mod=1e9+7;
const ll inf=1e18;

vector<int> v[maxn];
int dp[maxn];

void dfs(int u,int par){
    int id=-1, cnt=0;
    for(int y:v[u]){
	if(y!=par){
	    cnt++;
	    dfs(y,u);
	    if(id==-1 || dp[id]<dp[y])
		id=y;
	}
    }
    for(int y:v[u]){
	if(y!=par && y!=id)
	    dp[u]=max(dp[u], dp[y]);
    }
    dp[u]+=cnt;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie();

    int n,m,t; cin>>n>>m>>t;
    for(int i=0;i<n-1;i++){
	int a,b; cin>>a>>b;
	v[a].PB(b);
	v[b].PB(a);
    }
    dfs(m,t);
    return cout<<dp[m]<<endl,0;
}
// Deathly mistakes:
//  * Read the problem carefully.
//  * Check maxn.
//  * Overflows.


// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 23804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 399 ms 55160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 23804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 23804 KB Output isn't correct
2 Halted 0 ms 0 KB -