제출 #1325686

#제출 시각아이디문제언어결과실행 시간메모리
1325686pastaMousetrap (CEOI17_mousetrap)C++20
0 / 100
128 ms17104 KiB
//Oh? You're Approaching Me?
 
#include <bits/stdc++.h>
//#include <fstream>
using namespace std;
//  
#define int long long

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
 
 
// #pragma GCC optimize("O3,unroll-loops")
#define migmig     		    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb          		push_back
#define F           		first
#define S           		second
#define SZ(x)       		ll((x).size())
#define all(x)      		(x).begin(), (x).end()
#define cl          		clear
#define endl        		'\n'
#define deb(x)    			cerr << #x << " = " << x << '\n'
#define dokme(x)			{cout << x << endl; return;}
#define wtf					cout << "[ahaaaaaaaaaaaaaaaa]" << endl;
 
const int maxn = 2e5 + 100;
const int mod = 998244353;
const int inf = 1e18 + 5;
const int LOG = 61;
#define mid		((l + r) / 2)
#define lc		(id * 2)
#define rc		(lc + 1)
//g++ main.cpp -o main && main.exe

int n, m, t, dp[maxn];
vector<int> G[maxn];

void dfs(int u, int p) {
	int childs = 0;
	for (auto v : G[u])
		if(v != p)
			childs++;
	if(childs == 0)
	{
		dp[u] = 0;
		return;
	}
	int fir = 0, sec = 0;
	for (auto v : G[u])
	{
		if(v == p)
			continue;
		dfs(v, u);
		if(dp[v] > fir)
			sec = fir, fir = dp[v];
		else
		if(dp[v] > sec)
			sec = dp[v];
	}
	dp[u] = sec + childs;
	return;
}

signed main() {
	cin >> n >> t >> m;
	for (int i = 1; i < n; i++) {
		int v, u;
		cin >> v >> u;
		G[v].pb(u);
		G[u].pb(v);
	}
	dfs(m, t);
	cout << dp[m] << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...