CSES - NOI 2019 - Results
Submission details
Task:Distance Code
Sender:Carl Westerlund
Submission time:2019-03-06 13:00:53 +0200
Language:C++
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
#30
Test results
testverdicttimegroup
#1ACCEPTED0.02 s1, 2, 3details
#2ACCEPTED0.02 s1, 2, 3details
#3ACCEPTED0.02 s1, 2, 3details
#40.01 s1, 2, 3details
#50.01 s1, 2, 3details
#6ACCEPTED0.01 s1, 2, 3details
#70.01 s1, 2, 3details
#80.01 s1, 2, 3details
#90.02 s1, 2, 3details
#100.03 s1, 2, 3details
#110.01 s1, 2, 3details
#120.01 s2, 3details
#130.03 s2, 3details
#140.02 s2, 3details
#150.02 s2, 3details
#160.05 s3details
#170.04 s3details
#180.06 s3details
#190.04 s3details
#200.03 s1, 2, 3details

Code

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
#include "prettyprint.hpp"
#define PRINTLN(x) \
    cerr << x << "\n"
#define PRINTSP(x) \
    cerr << x << " "
#else
#define PRINTLN(x)
#define PRINTSP(x)
#endif

#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define PI 3.141592653589793238462643

template<class T> void amax(T & a, const T & b) { a = max(a,b); }
template<class T> void amin(T & a, const T & b) { a = min(a,b); }


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int r = 0;

    int cas, N;
    cin >> cas >> N;
    if (cas == 1) {
        vector<vector<int>> neis (N);
        for (int n=0; n < N-1; n++) {
            int a, b;
            cin >> a >> b;
            neis[a-1].push_back(b-1);
            neis[b-1].push_back(a-1);
        }
        vector<int> p (N, -1);
        vector<vector<int>> chs (N);
        vector<bool> vis (N, 0);
        queue<int> q;
        q.push(r);
        while (!q.empty()) {
            int cur = q.front(); q.pop();
            if (!vis[cur]) {
                vis[cur] = 1;
                for (auto nei : neis[cur]) {
                    if (nei != p[cur]) {
                        q.push(nei);
                        p[nei] = cur;
                        chs[cur].push_back(nei);
                    }
                }
            }
        }
        int cur = r;
        for (int i=0; i < N; i++) {
            while (!chs[cur].empty()) {
                int ncur = chs[cur].back();
                chs[cur].pop_back();
                cur = ncur;
            }
            cout << cur+1 << " ";
            cur = p[cur];
        }
    }
    else {
        vector<int> p (N, -1);
        int cur = r;
        vector<int> ds (N-1);
        for (int n=0; n < N-1; n++) {
            cin >> ds[n];
        }
        for (int n=N-2; n >= 0; n--) {
            int d = ds[n+1];
            for (int i=0; i < d-1; i++) {
               cur = p[cur];
            }
            p[n+1] = cur;
            cout << n+2 << " " << cur+1 << "\n";
            cur = n+1;
        }
    }
}

Test details

Test 1

Group: 1, 2, 3

Verdict: ACCEPTED

input
1
2
2 1

correct output
(empty)

user output
2 1

Test 2

Group: 1, 2, 3

Verdict: ACCEPTED

input
1
3
3 1
2 1

correct output
(empty)

user output
3 1
2 3

Test 3

Group: 1, 2, 3

Verdict: ACCEPTED

input
1
4
3 2
2 1
4 1

correct output
(empty)

user output
4 1
3 4
2 3

Test 4

Group: 1, 2, 3

Verdict:

input
1
4
2 3
3 4
1 3

correct output
(empty)

user output
4 1
3 4
2 3

Test 5

Group: 1, 2, 3

Verdict:

input
1
5
3 5
4 1
1 3
...

correct output
(empty)

user output
5 1
4 5
3 4
2 5

Test 6

Group: 1, 2, 3

Verdict: ACCEPTED

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

correct output
(empty)

user output
5 1
4 5
3 5
2 3

Test 7

Group: 1, 2, 3

Verdict:

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

correct output
(empty)

user output
5 1
4 5
3 4
2 4

Test 8

Group: 1, 2, 3

Verdict:

input
1
10
9 3
8 9
2 9
...

correct output
(empty)

user output
10 1
9 10
8 9
7 9
6 9
...

Test 9

Group: 1, 2, 3

Verdict:

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

correct output
(empty)

user output
10 1
9 10
8 9
7 8
6 7
...

Test 10

Group: 1, 2, 3

Verdict:

input
1
10
10 4
9 1
4 7
...

correct output
(empty)

user output
10 1
9 10
8 10
7 8
6 10
...

Test 11

Group: 1, 2, 3

Verdict:

input
1
10
2 6
4 3
3 5
...

correct output
(empty)

user output
10 1
9 10
8 9
7 8
6 7
...

Test 12

Group: 2, 3

Verdict:

input
1
500
10 6
6 255
6 428
...

correct output
(empty)

user output
500 1
499 500
498 499
497 499
496 499
...
Truncated

Test 13

Group: 2, 3

Verdict:

input
1
500
152 466
451 313
158 479
...

correct output
(empty)

user output
500 1
499 500
498 499
497 498
496 497
...
Truncated

Test 14

Group: 2, 3

Verdict:

input
1
500
109 440
330 190
443 161
...

correct output
(empty)

user output
500 1
499 500
498 500
497 498
496 497
...
Truncated

Test 15

Group: 2, 3

Verdict:

input
1
500
144 373
257 233
341 318
...

correct output
(empty)

user output
500 1
499 500
498 499
497 498
496 497
...
Truncated

Test 16

Group: 3

Verdict:

input
1
100000
54983 75172
93807 75172
44082 75172
...

correct output
(empty)

user output
100000 1
99999 100000
99998 99999
99997 99999
99996 99999
...
Truncated

Test 17

Group: 3

Verdict:

input
1
100000
88863 19059
86423 76688
98536 95984
...

correct output
(empty)

user output
100000 1
99999 100000
99998 99999
99997 99998
99996 99997
...
Truncated

Test 18

Group: 3

Verdict:

input
1
100000
59979 6389
19097 24999
27846 82330
...

correct output
(empty)

user output
100000 1
99999 100000
99998 100000
99997 99998
99996 99997
...
Truncated

Test 19

Group: 3

Verdict:

input
1
100000
58761 66001
25102 51081
98625 67861
...

correct output
(empty)

user output
100000 1
99999 100000
99998 99999
99997 99998
99996 99997
...
Truncated

Test 20

Group: 1, 2, 3

Verdict:

input
1
6
2 1
3 2
4 2
...

correct output
(empty)

user output
6 1
5 6
4 5
3 4
2 4