답안 #1011364

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1011364 2024-06-30T12:27:45 Z NValchanov Mousetrap (CEOI17_mousetrap) C++17
25 / 100
615 ms 90192 KB
#include<bits/stdc++.h>
 
#define endl '\n'
 
using namespace std;
 
typedef long long ll;
 
const ll MAXN = 1e6 + 10;
 
ll n, start, finish;
vector < ll > adj[MAXN];
ll dp[MAXN];
ll deg[MAXN];
 
void dfs(ll u, ll par)
{
    priority_queue < ll > pq;
 
    for(ll v : adj[u])
    {
        if(v == par)
            continue;
 
        dfs(v, u);
        pq.push(dp[v]);
    }
 
    if(pq.size() == 1)
        dp[u] = 1;
    else if(pq.size() >= 2)
    {
        pq.pop();
        ll cur = pq.top();
 
        if(u == par)
            dp[u] = deg[u] + cur;
        else
            dp[u] = deg[u] + cur - 1;
    }
 
}
 
void read()
{
    cin >> n >> finish >> start;
    for(int i = 1; i <= n - 1; i ++)
    {
        ll u,v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
        deg[u]++;
        deg[v]++;
    }
}
 
void solve()
{
    dfs(start, start);
 
    cout << dp[start] - 1 << endl;
}
 
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
 
    read();
    solve();
 
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 245 ms 87992 KB Output is correct
2 Correct 199 ms 81488 KB Output is correct
3 Correct 587 ms 90192 KB Output is correct
4 Correct 251 ms 56860 KB Output is correct
5 Correct 615 ms 89952 KB Output is correct
6 Correct 604 ms 90024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 10 ms 23896 KB Output isn't correct
2 Halted 0 ms 0 KB -