42032023-03-16 09:31:461478Utazási irodacpp17Elfogadva 45/4598ms22796 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())

const int N_MAX = 1e5 + 1;
long long k;
vector<vector<int>> a(N_MAX);
vector<bool> lattam(N_MAX);
int db = 0;
bool b = 0;
deque<int> ans;
void melysegi(int node){
    ans.push_back(node);
    db++;
    if(db == k){
        if(!b){
            //cout << "**";
            while(!ans.empty()){
                cout << ans.front() << " ";
                ans.pop_front();
            }
            b = 1;
        }
        return;
    }
    else{
        for(int i = 0; i < a[node].size(); i++){
            if(!lattam[a[node][i]]){
                lattam[a[node][i]] = 1;
                melysegi(a[node][i]);
            }
        }
    }

    if(!ans.empty()){
        ans.pop_back();
    }
}

int main()
{
    //fast_cin();
    //ifstream cin("in.txt");
    long long n;
    cin>>n>>k;
    for(int i=1; i<n; i++){
        int x, y;
        cin>>x>>y;
        a[x].push_back(y);
        a[y].push_back(x);
    }
    for(int i=1; i<=n; i++){
        sort(a[i].begin(), a[i].end());
    }
    int node;
    if(n%k == 0){
        node = k/n;
        k = n;
    }
    else{
        node = k/n+1;
        k = k%n;
    }
    //deque<int> ans;
    lattam[node] = 1;
    melysegi(node);

    return 0;
}
/*

10 26
1 2
2 9
2 4
4 10
3 5
5 10
5 7
5 6
10 8
*/
RészfeladatÖsszpontTesztVerdiktIdőMemória
base45/45
1Elfogadva0/04ms6352 KiB
2Elfogadva0/014ms7500 KiB
3Elfogadva2/24ms6720 KiB
4Elfogadva2/24ms6680 KiB
5Elfogadva1/14ms6936 KiB
6Elfogadva2/26ms7020 KiB
7Elfogadva2/26ms7256 KiB
8Elfogadva1/16ms7924 KiB
9Elfogadva2/294ms22320 KiB
10Elfogadva2/297ms22796 KiB
11Elfogadva1/197ms17676 KiB
12Elfogadva2/296ms14164 KiB
13Elfogadva2/290ms15084 KiB
14Elfogadva2/293ms14648 KiB
15Elfogadva2/293ms14368 KiB
16Elfogadva2/290ms15360 KiB
17Elfogadva3/393ms15040 KiB
18Elfogadva2/298ms14832 KiB
19Elfogadva2/294ms14984 KiB
20Elfogadva2/293ms15584 KiB
21Elfogadva3/396ms15304 KiB
22Elfogadva3/393ms15280 KiB
23Elfogadva3/394ms15668 KiB
24Elfogadva1/194ms15672 KiB
25Elfogadva1/194ms16276 KiB