38192023-03-03 09:49:121478Utazási irodacpp17Hibás válasz 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base24/45
1Elfogadva0/04ms7908 KiB
2Elfogadva0/09ms9152 KiB
3Hibás válasz0/24ms8316 KiB
4Elfogadva2/24ms8268 KiB
5Hibás válasz0/14ms8396 KiB
6Hibás válasz0/24ms8656 KiB
7Elfogadva2/24ms8608 KiB
8Hibás válasz0/110ms17380 KiB
9Futási hiba0/283ms128152 KiB
10Futási hiba0/282ms127948 KiB
11Futási hiba0/193ms127728 KiB
12Elfogadva2/246ms15680 KiB
13Elfogadva2/245ms16932 KiB
14Hibás válasz0/2158ms111444 KiB
15Elfogadva2/254ms15948 KiB
16Elfogadva2/254ms16868 KiB
17Elfogadva3/3108ms89716 KiB
18Hibás válasz0/290ms18900 KiB
19Hibás válasz0/2136ms27424 KiB
20Hibás válasz0/2224ms103860 KiB
21Elfogadva3/365ms18912 KiB
22Elfogadva3/359ms34968 KiB
23Elfogadva3/375ms44172 KiB
24Futási hiba0/1105ms126876 KiB
25Futási hiba0/1101ms126648 KiB