CSES - Aalto Competitive Programming 2024 - wk12 - Mon - Results
Submission details
Task:Creating Offices
Sender:aalto2024m_002
Submission time:2024-11-25 20:29:02 +0200
Language:C++ (C++20)
Status:READY
Result:
Test results
testverdicttime
#10.01 sdetails
#20.01 sdetails
#30.01 sdetails
#40.01 sdetails
#50.01 sdetails
#60.15 sdetails
#70.16 sdetails
#80.15 sdetails
#90.15 sdetails
#100.14 sdetails
#110.15 sdetails
#120.09 sdetails
#130.13 sdetails
#140.14 sdetails
#150.17 sdetails
#160.07 sdetails
#170.11 sdetails
#180.01 sdetails
#190.08 sdetails
#200.10 sdetails
#210.01 sdetails
#220.10 sdetails

Code

#ifdef ONPC
    #define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

#define char unsigned char
#define rep(i, a, b) for(int i=a; i< (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back

#define LSOne(S) ((S) & -(S))

using namespace std;
// mt19937 rnd(239);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

template <typename T> int sgn(T x) { return (T(0) < x) - (x < T(0)); }
typedef long double T;
typedef complex<T> pt;
#define X real()
#define Y imag()

template<class T>
istream& operator>> (istream& is, complex<T>& p) {
    T value;
    is >> value;
    p.real(value);
    is >> value;
    p.imag(value);
    return is;
}

typedef long long ll;
typedef long double ld;

using pi = pair<ll, ll>;
using vi = vector<ll>;
template <class T>
using pq = priority_queue<T>;
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;

int popcnt(int x) { return __builtin_popcount(x); }
int popcnt(ll x) { return __builtin_popcountll(x); }

#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define LB(c, x) distance((c).begin(), lower_bound(all(c), (x)))
#define UB(c, x) distance((c).begin(), upper_bound(all(c), (x)))

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef DEBUG
#define dbg(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define dbg(x...)
#endif

template<typename S, typename T = S> void chmin(S &s, T t) {s = s < t ? s : t;}
template<typename S, typename T = S> void chmax(S &s, T t) {s = s > t ? s : t;}

const int INF = 1e9; // 10^9 = 1B is < 2^31-1
const ll LLINF = 4e18; // 4*10^18 is < 2^63-1
const double EPS = 1e-9;
const ll MOD = 1e9+7;


const int N=2e5+10;
vector<int> adj[N];
ll dp[N];
vector<int> poss;
int d;

void dfs(int node, int prev, int dist) {
    if(dist>=d) {
        poss.pb(node);
        dist=0;
    }
    for(auto &w:adj[node]) {
        if(w==prev) continue;
        dfs(w, node, dist+1);
    }
    
}

int solve() {
    int n; std::cin >> n >> d;
    for (int i = 0; i < n-1; i++) {
        int a,b; std::cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }


    for (int i = 1; i <= n; i++) {
        if(adj[i].size()==1) {
            dfs(i, -1, 0);
            break;
        }
    }

    std::cout << poss.size() << std::endl;
    for(auto &w:poss) {
        std::cout << w << " ";
    }
    std::cout  << std::endl;
    //__print(poss); std::cout  << std::endl;

    

    return 0;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1;
    //cin >> TET;
    for (int i = 1; i <= TET; i++) {
        #ifdef ONPC
            cout << "TEST CASE#" << i << endl;
        #endif
        
        if (solve()) {
            break;
        }

        #ifdef ONPC
            cout << "__________________________" << endl;
        #endif
    }
    #ifdef ONPC
        cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
    #endif
}

Test details

Test 1

Verdict:

input
10 3
5 10
8 7
1 4
3 5
...

correct output
4
1 3 8 9 

user output
3
1 3 9 

Test 2

Verdict:

input
10 5
8 7
8 2
8 5
8 3
...

correct output
1
10 

user output
0

Test 3

Verdict:

input
10 5
3 7
7 10
7 8
9 1
...

correct output
2
1 4 

user output
1

Test 4

Verdict:

input
10 4
8 5
8 6
1 8
4 9
...

correct output
3
3 9 10 

user output
3
5 6 4 

Test 5

Verdict:

input
10 3
7 8
1 10
4 3
1 5
...

correct output
4
3 8 9 10 

user output
3
10 5 7 

Test 6

Verdict:

input
200000 9
7112 139320
131799 678
101561 62983
190924 56029
...

correct output
22223
7 27 28 29 34 35 53 63 65 71 7...

user output
22222
173442 43755 139047 90021 4199...
Truncated

Test 7

Verdict:

input
200000 1
117863 108209
117863 142206
117863 98558
117863 124329
...

correct output
200000
1 2 3 4 5 6 7 8 9 10 11 12 13 ...

user output
199999
117863 108209 142206 98558 124...
Truncated

Test 8

Verdict:

input
200000 2
196127 1313
59937 27170
188592 185528
106118 64586
...

correct output
119174
1 2 7 8 9 10 11 14 16 17 18 19...

user output
100122
125432 106982 78631 188095 130...
Truncated

Test 9

Verdict:

input
200000 3
174335 181372
73884 35338
65409 30522
120927 7911
...

correct output
66675
10 30 31 39 42 46 48 52 54 55 ...

user output
66666
125343 170618 125294 17683 186...
Truncated

Test 10

Verdict:

input
200000 9
156193 90960
92081 42156
64080 41287
65601 109953
...

correct output
22257
8 14 30 42 59 62 74 82 99 103 ...

user output
22220
92332 101647 84275 68046 18362...
Truncated

Test 11

Verdict:

input
200000 200000
183551 137559
138103 16820
21892 134252
182028 187950
...

correct output
1
40760 

user output
0

Test 12

Verdict:

input
200000 459
30507 105253
30507 95541
30507 161230
30507 135274
...

correct output
1
200000 

user output
0

Test 13

Verdict:

input
200000 327
43832 190820
78666 45374
184224 57261
193962 158173
...

correct output
1
181355 

user output
0

Test 14

Verdict:

input
200000 217
31004 146202
108924 82624
43788 48134
199877 157947
...

correct output
924
279 304 418 471 539 566 713 10...

user output
914
29364 51445 85852 40922 149564...
Truncated

Test 15

Verdict:

input
200000 475
77454 87171
23492 138432
137402 34171
181862 18661
...

correct output
394
833 915 982 2281 2467 2531 267...

user output
413
143774 38258 93526 198346 2217...
Truncated

Test 16

Verdict:

input
199999 4
1 2
2 3
1 4
4 5
...

correct output
99999
3 5 7 9 11 13 15 17 19 21 23 2...

user output
99998
5 7 9 11 13 15 17 19 21 23 25 ...
Truncated

Test 17

Verdict:

input
199397 946
29518 79973
29518 71183
71183 194147
29518 156561
...

correct output
159
52 101 164 243 252 621 1256 37...

user output
266
106223 195032 108122 72593 180...
Truncated

Test 18

Verdict:

input
5 3
1 2
2 3
3 4
3 5

correct output
2
1 5 

user output
2
4 5 

Test 19

Verdict:

input
199397 5000
1 2
2 3
3 4
4 5
...

correct output
40
4397 9397 14397 19397 24397 29...

user output
39
5001 10001 15001 20001 25001 3...
Truncated

Test 20

Verdict:

input
199397 945
29518 79973
29518 71183
71183 194147
29518 156561
...

correct output
160
52 101 164 243 252 621 1256 37...

user output
267
57445 160880 80367 44874 27853...
Truncated

Test 21

Verdict:

input
1 1

correct output
1

user output
0

Test 22

Verdict:

input
199397 899
29518 79973
29518 71183
71183 194147
29518 156561
...

correct output
183
52 101 164 243 252 621 792 125...

user output
313
88029 22046 50222 21567 91551 ...
Truncated