66962023-12-16 22:14:18anonUtazási irodacpp17Time limit exceeded 41/451.065s81008 KiB
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
typedef long long ll;
using namespace std;
const ll INF = ~(1LL << 63);
ll K;
vector<set<ll>> G;
vector<bool> vis;
unordered_map<ll, ll> DP;
bool rec(ll node, stack<ll> &s) {
    ll origK, key;
    vis[node] = true;
    if(!--K) {
        s.push(node);
        return true;
    }
    for(const auto &x : G[node]) {
        if(vis[x])
            continue;
        key = node | (x << 32);
        auto found = DP.find(key);
        if(found != DP.end() && K > found->second) {
            K -= found->second;
            continue;
        }
        origK = K;
        if(rec(x, s)) {
            s.push(node);
            return true;
        }
        DP[key] = origK - K;
    }
    return false;
}
int main() {
    FastIO;
    ll i, N, n1, n2;
    set<ll> ns;
    cin >> N >> K;
    G.resize(N + 1);
    vis.resize(N + 1);
    for(i = 1; i < N; i++) {
        cin >> n1 >> n2;
        G[n1].insert(n2);
        G[n2].insert(n1);
        ns.insert(n1);
        ns.insert(n2);
    }
    for(auto it = ns.begin(); it != ns.end(); it++) {
        stack<ll> s;
        fill(vis.begin() + 1, vis.end(), false);
        if(rec(*it, s)) {
            while(!s.empty()) {
                cout << s.top() << ' ';
                s.pop();
            }
            cout << '\n';
            return 0;
        }
    }
    return 1;
}

SubtaskSumTestVerdictTimeMemory
base41/45
1Accepted0/03ms1892 KiB
2Accepted0/025ms8976 KiB
3Accepted2/23ms2620 KiB
4Accepted2/23ms2556 KiB
5Accepted1/13ms2592 KiB
6Accepted2/24ms3716 KiB
7Accepted2/214ms3676 KiB
8Accepted1/16ms4208 KiB
9Accepted2/2287ms75240 KiB
10Accepted2/2303ms81008 KiB
11Accepted1/1296ms73968 KiB
12Accepted2/2270ms53576 KiB
13Time limit exceeded0/21.065s26036 KiB
14Accepted2/2301ms60592 KiB
15Accepted2/2407ms59572 KiB
16Time limit exceeded0/21.052s26272 KiB
17Accepted3/3230ms54624 KiB
18Accepted2/2314ms60180 KiB
19Accepted2/2221ms53792 KiB
20Accepted2/2384ms61232 KiB
21Accepted3/3363ms60708 KiB
22Accepted3/3393ms60864 KiB
23Accepted3/3233ms55476 KiB
24Accepted1/1202ms54080 KiB
25Accepted1/1210ms55420 KiB