66952023-12-16 21:30:50anonUtazási irodacpp17Time limit exceeded 10/451.1s27656 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;
bool rec(ll node, stack<ll> &s) {
    vis[node] = true;
    if(!--K) {
        s.push(node);
        return true;
    }
    for(const auto &x : G[node]) {
        if(!vis[x] && rec(x, s)) {
            s.push(node);
            return true;
        }
    }
    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
base10/45
1Accepted0/03ms1972 KiB
2Time limit exceeded0/01.1s3860 KiB
3Accepted2/23ms2412 KiB
4Accepted2/23ms2624 KiB
5Accepted1/14ms2944 KiB
6Accepted2/282ms3840 KiB
7Accepted2/224ms3940 KiB
8Accepted1/1162ms3912 KiB
9Time limit exceeded0/21.072s27420 KiB
10Time limit exceeded0/21.075s27552 KiB
11Time limit exceeded0/11.055s27656 KiB
12Time limit exceeded0/21.019s21416 KiB
13Time limit exceeded0/21.059s21400 KiB
14Time limit exceeded0/21.059s21660 KiB
15Time limit exceeded0/21.07s21464 KiB
16Time limit exceeded0/21.07s21400 KiB
17Time limit exceeded0/31.05s21876 KiB
18Time limit exceeded0/21.059s21600 KiB
19Time limit exceeded0/21.059s21788 KiB
20Time limit exceeded0/21.07s21960 KiB
21Time limit exceeded0/31.07s21660 KiB
22Time limit exceeded0/31.067s21952 KiB
23Time limit exceeded0/31.067s22164 KiB
24Time limit exceeded0/11.05s22388 KiB
25Time limit exceeded0/11.07s22772 KiB