/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 4ms 5.32 MiB
#2 Accepted 4ms 5.277 MiB
#3 Accepted 4ms 5.02 MiB
#4 Wrong Answer 4ms 5.012 MiB
#5 Wrong Answer 46ms 12.004 MiB

Code

#define _GLIBCXX_FILESYSTEM
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt")

int n,k;
const int N = 2e5+5;

vector<int> g[N];
int mx;

void dfs(int u,int p = 0,int d = 1) {
    mx = max(mx, d);
    for(auto x: g[u]) {
        if(x == p) continue;
        dfs(x,u,d+1);
    }
    return;
}
void solve() {
    cin >> n >> k;
    for(int i = 1; i < n; i++) {
        int u,v;
        cin >> u >> v;
        g[u].push_back(v);
        g[v].push_back(u);
    }
    dfs(1);
    cout << min(n, k + mx) << '\n';
    return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int tc = 1;
    // cin >> tc;
    for(int kase = 1; kase <= tc; kase++) {
        //cout << "Case " << kase << ": ";
        solve();
    }
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1111 Thakurs tree game
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-06 04:52:34
Judged At
2024-11-06 04:52:34
Judged By
Score
10
Total Time
46ms
Peak Memory
12.004 MiB