63782023-11-26 10:28:19horvathabelUtazási irodacpp17Accepted 45/4568ms39520 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
ll n,k;
vector<ll> g[100001];
vector<ll> p;
ll cnt=0;
vector<bool> seen;
void dfs(ll x,ll k, ll s){
    cnt++;
    seen[x]=true;
    if (cnt==k){
        int most=x;
        vector<ll> ans;
        while (most!=0){
            ans.push_back(most);
            most=p[most];
        }
        reverse(ans.begin(), ans.end());
        for (ll c:ans) cout<<c<<" ";
        return;
    }
    for (ll edge:g[x]){
        if (!seen[edge]){
            p[edge]=x;
            dfs(edge,k,s);
        }
    }

}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>k;
    seen.resize(n+1,false);
    p.resize(n+1,0);
    for (ll i=1; i<n;i++){
        ll a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    for (ll i=1; i<=n;i++) sort(g[i].begin(), g[i].end());
    k+=n;
    ll z=k/n;
    if (k%n==0){
        z--;
    }
    cnt=(z-1)*n;
    dfs(z,k-n,z);
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base45/45
1Accepted0/04ms6600 KiB
2Accepted0/09ms8256 KiB
3Accepted2/24ms7024 KiB
4Accepted2/24ms7328 KiB
5Accepted1/14ms7692 KiB
6Accepted2/24ms7632 KiB
7Accepted2/26ms7912 KiB
8Accepted1/14ms8112 KiB
9Accepted2/263ms29812 KiB
10Accepted2/263ms31808 KiB
11Accepted1/157ms26252 KiB
12Accepted2/257ms21804 KiB
13Accepted2/252ms24128 KiB
14Accepted2/252ms24972 KiB
15Accepted2/268ms25812 KiB
16Accepted2/252ms28088 KiB
17Accepted3/356ms28940 KiB
18Accepted2/256ms29624 KiB
19Accepted2/256ms30840 KiB
20Accepted2/257ms32704 KiB
21Accepted3/354ms32964 KiB
22Accepted3/356ms34300 KiB
23Accepted3/356ms36108 KiB
24Accepted1/156ms37512 KiB
25Accepted1/154ms39520 KiB