Submission #483328

# Submission time Handle Problem Language Result Execution time Memory
483328 2021-10-28T17:43:45 Z lukaszgniecki Stations (IOI20_stations) C++17
100 / 100
892 ms 740 KB
#include "stations.h"
#include <bits/stdc++.h>

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvvvi vector<vvvi>
#define vll vector<ll>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vvvvll vector<vvvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)

using namespace std;

int find_next_station(int s, int t, vi neib) {
    if (neib.size() == 1)
        return neib[0];

    if (s < neib[0]) {
        int prev = s;
        for (int x : neib) {
            if (t > prev && t <= x) {
                return x;
            }
            prev = x;
        }
        return neib.back();
    }
    else {
        int prev = s;
        for (int i = neib.size() - 1; i >= 0; i--) {
            int x = neib[i];
            if (t < prev && t >= x) {
                return x;
            }
            prev = x;
        }
        return neib[0];
    }
}

void dfs_label(vvi & tr, int x, int p, int lvl, vi & lab, int & mx) {
    if (lvl & 1) {
        for (int y : tr[x]) {
            if (y != p) {
                dfs_label(tr, y, x, lvl + 1, lab, mx);
            }
        }
        lab[x] = mx + 1;
        mx = lab[x];
    }
    else {
        lab[x] = mx + 1;
        mx = lab[x];
        for (int y : tr[x]) {
            if (y != p) {
                dfs_label(tr, y, x, lvl + 1, lab, mx);
            }
        }
    }
}

vi label(int n, int k, vi u, vi v) {
    vvi tr(n);
    rep(i, 0, n - 1) {
        tr[u[i]].push_back(v[i]);
        tr[v[i]].push_back(u[i]);
    }
    vi lab(n, -1);
    int mx = -1;
    dfs_label(tr, 0, 0, 0, lab, mx);
    return lab;
}

/*
int main() {
    vi lab = label(5, 10, {0, 1, 1, 2}, {1, 2, 3, 4});
    rep(i, 0, 5) {
        cout << lab[i] << " ";
    }
    cout << endl;
    */
/*cout << 0 << " " << 4 << " " << find_next_station(0, 4, {4}) << '\n';
    cout << 3 << " " << 2 << " " << find_next_station(3, 2, {4})<< '\n';
    cout << 3 << " " << 0 << " " << find_next_station(3, 0, {4})<< '\n';
    cout << 4 << " " << 0 << " " << find_next_station(4, 0, {0, 1, 3})<< '\n';
    cout << 4 << " " << 2 << " " << find_next_station(4, 2, {0, 1, 3})<< '\n';
    cout << 4 << " " << 3 << " " << find_next_station(4, 3, {0, 1, 3})<< '\n';*//*


    lab = label(2, 1, {0}, {1});
    for (int x : lab) cout << x << " ";
    cout << endl;

    lab = label(4, 3, {0, 0, 0}, {1, 2, 3});
    for (int x : lab) cout << x << " ";
    cout << endl;
}*/
# Verdict Execution time Memory Grader output
1 Correct 482 ms 644 KB Output is correct
2 Correct 458 ms 616 KB Output is correct
3 Correct 831 ms 400 KB Output is correct
4 Correct 517 ms 400 KB Output is correct
5 Correct 618 ms 400 KB Output is correct
6 Correct 443 ms 612 KB Output is correct
7 Correct 377 ms 528 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 392 ms 488 KB Output is correct
2 Correct 475 ms 528 KB Output is correct
3 Correct 771 ms 400 KB Output is correct
4 Correct 578 ms 400 KB Output is correct
5 Correct 446 ms 484 KB Output is correct
6 Correct 330 ms 528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 474 ms 528 KB Output is correct
2 Correct 395 ms 656 KB Output is correct
3 Correct 645 ms 472 KB Output is correct
4 Correct 520 ms 400 KB Output is correct
5 Correct 514 ms 400 KB Output is correct
6 Correct 398 ms 656 KB Output is correct
7 Correct 405 ms 612 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 4 ms 468 KB Output is correct
10 Correct 0 ms 468 KB Output is correct
11 Correct 472 ms 484 KB Output is correct
12 Correct 419 ms 688 KB Output is correct
13 Correct 476 ms 740 KB Output is correct
14 Correct 467 ms 484 KB Output is correct
15 Correct 53 ms 400 KB Output is correct
16 Correct 65 ms 528 KB Output is correct
17 Correct 105 ms 532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 828 ms 540 KB Output is correct
2 Correct 612 ms 400 KB Output is correct
3 Correct 592 ms 492 KB Output is correct
4 Correct 2 ms 480 KB Output is correct
5 Correct 4 ms 476 KB Output is correct
6 Correct 1 ms 476 KB Output is correct
7 Correct 503 ms 492 KB Output is correct
8 Correct 851 ms 400 KB Output is correct
9 Correct 628 ms 400 KB Output is correct
10 Correct 699 ms 488 KB Output is correct
11 Correct 5 ms 468 KB Output is correct
12 Correct 6 ms 468 KB Output is correct
13 Correct 4 ms 468 KB Output is correct
14 Correct 3 ms 476 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 574 ms 488 KB Output is correct
17 Correct 503 ms 488 KB Output is correct
18 Correct 488 ms 420 KB Output is correct
19 Correct 515 ms 400 KB Output is correct
20 Correct 490 ms 472 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 420 ms 520 KB Output is correct
2 Correct 333 ms 520 KB Output is correct
3 Correct 892 ms 400 KB Output is correct
4 Correct 627 ms 400 KB Output is correct
5 Correct 455 ms 400 KB Output is correct
6 Correct 401 ms 656 KB Output is correct
7 Correct 409 ms 492 KB Output is correct
8 Correct 2 ms 476 KB Output is correct
9 Correct 3 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 356 ms 476 KB Output is correct
12 Correct 441 ms 520 KB Output is correct
13 Correct 748 ms 400 KB Output is correct
14 Correct 499 ms 488 KB Output is correct
15 Correct 511 ms 528 KB Output is correct
16 Correct 385 ms 528 KB Output is correct
17 Correct 585 ms 400 KB Output is correct
18 Correct 412 ms 528 KB Output is correct
19 Correct 379 ms 520 KB Output is correct
20 Correct 444 ms 528 KB Output is correct
21 Correct 58 ms 468 KB Output is correct
22 Correct 58 ms 576 KB Output is correct
23 Correct 110 ms 580 KB Output is correct
24 Correct 2 ms 468 KB Output is correct
25 Correct 5 ms 468 KB Output is correct
26 Correct 3 ms 472 KB Output is correct
27 Correct 4 ms 480 KB Output is correct
28 Correct 0 ms 468 KB Output is correct
29 Correct 386 ms 400 KB Output is correct
30 Correct 474 ms 400 KB Output is correct
31 Correct 367 ms 400 KB Output is correct
32 Correct 501 ms 400 KB Output is correct
33 Correct 465 ms 400 KB Output is correct
34 Correct 338 ms 556 KB Output is correct
35 Correct 344 ms 648 KB Output is correct
36 Correct 436 ms 732 KB Output is correct
37 Correct 458 ms 488 KB Output is correct
38 Correct 288 ms 604 KB Output is correct
39 Correct 289 ms 608 KB Output is correct
40 Correct 432 ms 484 KB Output is correct
41 Correct 382 ms 480 KB Output is correct
42 Correct 57 ms 528 KB Output is correct
43 Correct 105 ms 508 KB Output is correct
44 Correct 118 ms 548 KB Output is correct
45 Correct 146 ms 528 KB Output is correct
46 Correct 224 ms 656 KB Output is correct
47 Correct 232 ms 612 KB Output is correct
48 Correct 50 ms 532 KB Output is correct
49 Correct 52 ms 660 KB Output is correct