42002023-03-16 08:34:221478Utazási irodacpp17Wrong answer 24/45203ms127724 KiB
#include <bits/stdc++.h>
#include <random>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> p32;
typedef pair<ll, ll> p64;
typedef pair<double, double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int>> vv32;
typedef vector<vector<ll>> vv64;
typedef vector<vector<p64>> vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i, e) for (ll i = 0; i < e; i++)
#define forsn(i, s, e) for (ll i = s; i < e; i++)
#define rforn(i, s) for (ll i = s; i >= 0; i--)
#define rforsn(i, s, e) for (ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout << #x << " = " << x << ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define fast_cin()                    \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())

vector<priority_queue<int, vector<int>, greater<int>>> adjacent(100000);
int n;
bool solution = 0;
long long k;
int db = 0;
vector<bool> seen(100000);

void dfs(int node, deque<int> kju)
{
    if (kju.size() < k && !solution)
    {
        seen[node] = true;
        db++;
        kju.push_back(node);
        while (!adjacent[node].empty() && !solution)
        {
            if (!seen[adjacent[node].top()])
                dfs(adjacent[node].top(), kju);
            adjacent[node].pop();
        }

        //kju.pop_back();
    }
    if (db == k && !solution)
    {
        //cout << "*" << '\n';
        while (!kju.empty())
        {
            cout << kju.front() << " ";
            kju.pop_front();
        }
        solution = 1;
    }

}

int main()
{
    fast_cin();
    //ifstream cin("in.txt");
    cin >> n;
    cin >> k;
    for (int i = 1; i < n; i++)
    {
        int x, y;
        cin >> x >> y;
        adjacent[x].push(y);
        adjacent[y].push(x);
    }
    /*for(int i=1; i<=n; i++){
        sort(adjacent[i].begin(), adjacent[i].end());
    }*/

    //cout << n << " " << k << '\n';
    int node;
    if (k % n == 0)
    {
        node = k / n;
        k = n;
    }
    else
    {
        node = k / n + 1;
        k = k % n;
    }
    //cout<<k<<'\n';
    deque<int> kju;
    dfs(node, kju);



    return 0;
}
SubtaskSumTestVerdictTimeMemory
base24/45
1Accepted0/06ms7912 KiB
2Accepted0/08ms9072 KiB
3Wrong answer0/24ms8328 KiB
4Accepted2/24ms8288 KiB
5Wrong answer0/14ms8416 KiB
6Wrong answer0/26ms8668 KiB
7Accepted2/26ms8864 KiB
8Wrong answer0/110ms17852 KiB
9Runtime error0/282ms127724 KiB
10Runtime error0/279ms127492 KiB
11Runtime error0/193ms127464 KiB
12Accepted2/246ms15952 KiB
13Accepted2/245ms17136 KiB
14Wrong answer0/2159ms111956 KiB
15Accepted2/256ms16384 KiB
16Accepted2/256ms17628 KiB
17Accepted3/397ms90432 KiB
18Wrong answer0/290ms19584 KiB
19Wrong answer0/2143ms27980 KiB
20Wrong answer0/2203ms104432 KiB
21Accepted3/364ms19480 KiB
22Accepted3/357ms35660 KiB
23Accepted3/368ms44712 KiB
24Runtime error0/194ms126408 KiB
25Runtime error0/1101ms126308 KiB