38192023-03-03 09:49:121478Utazási irodacpp17Wrong answer 24/45224ms128152 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);
    }
    //cout << n << " " << k << '\n';
    int node;
    if (k % n == 0)
    {
        k = n;
        node = 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/04ms7908 KiB
2Accepted0/09ms9152 KiB
3Wrong answer0/24ms8316 KiB
4Accepted2/24ms8268 KiB
5Wrong answer0/14ms8396 KiB
6Wrong answer0/24ms8656 KiB
7Accepted2/24ms8608 KiB
8Wrong answer0/110ms17380 KiB
9Runtime error0/283ms128152 KiB
10Runtime error0/282ms127948 KiB
11Runtime error0/193ms127728 KiB
12Accepted2/246ms15680 KiB
13Accepted2/245ms16932 KiB
14Wrong answer0/2158ms111444 KiB
15Accepted2/254ms15948 KiB
16Accepted2/254ms16868 KiB
17Accepted3/3108ms89716 KiB
18Wrong answer0/290ms18900 KiB
19Wrong answer0/2136ms27424 KiB
20Wrong answer0/2224ms103860 KiB
21Accepted3/365ms18912 KiB
22Accepted3/359ms34968 KiB
23Accepted3/375ms44172 KiB
24Runtime error0/1105ms126876 KiB
25Runtime error0/1101ms126648 KiB