Submission #307052

# Submission time Handle Problem Language Result Execution time Memory
307052 2020-09-26T21:19:10 Z VEGAnn Stations (IOI20_stations) C++14
100 / 100
1101 ms 1296 KB
#include "stations.h"
#include <bits/stdc++.h>
#define PB push_back
#define sz(x) ((int)x.size())
#define all(x) x.begin(),x.end()
using namespace std;
vector<int> g[1000];
int tin[1000], tout[1000], tt = 0, ht[1000];

void dfs(int v, int p, bool tp){
    tin[v] = tt;

    if (!tp) tt++;

    ht[v] = tp;

    for (int u : g[v]){
        if (u == p) continue;
        dfs(u, v, tp ^ 1);
    }

    tout[v] = tt;

    if (tp) tt++;
}

std::vector<int> label(int n, int k, std::vector<int> u, std::vector<int> v) {
    for (int i = 0; i < n; i++)
        g[i].clear();

    tt = 0;

    for (int i = 0; i < sz(u); i++){
        g[u[i]].PB(v[i]);
        g[v[i]].PB(u[i]);
    }

    dfs(0, -1, 0);

    vector<int> labels;

    labels.resize(n);

    for (int i = 0; i < n; i++) {
        if (ht[i] == 0)
            labels[i] = tin[i];
        else labels[i] = tout[i];
    }

	return labels;
}

int find_next_station(int s, int t, std::vector<int> c) {
    int ss = s;

    int tt = t;

    if (c.back() > s){
        if (ss > tt) return c.back();

        int siz = sz(c);

        int lst = c.back();

        if (s > 0) {
            if (sz(c) > 1)
                lst = c[siz - 2];
            else lst = -1;
        }

        if (tt <= lst){
            for (int v : c)
                if (tt <= v)
                    return v;
        } else return c.back();
    } else {
        if (ss < tt) return c[0];

        if (sz(c) > 1 && tt >= c[1]){
            reverse(all(c));

            for (int v : c)
                if (tt >= v)
                    return v;
        } else return c[0];
    }
}

Compilation message

stations.cpp: In function 'int find_next_station(int, int, std::vector<int>)':
stations.cpp:87:1: warning: control reaches end of non-void function [-Wreturn-type]
   87 | }
      | ^
# Verdict Execution time Memory Grader output
1 Correct 604 ms 1024 KB Output is correct
2 Correct 485 ms 1024 KB Output is correct
3 Correct 1009 ms 1024 KB Output is correct
4 Correct 755 ms 872 KB Output is correct
5 Correct 717 ms 872 KB Output is correct
6 Correct 556 ms 1272 KB Output is correct
7 Correct 541 ms 928 KB Output is correct
8 Correct 2 ms 780 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 450 ms 812 KB Output is correct
2 Correct 681 ms 820 KB Output is correct
3 Correct 1001 ms 768 KB Output is correct
4 Correct 786 ms 1024 KB Output is correct
5 Correct 643 ms 868 KB Output is correct
6 Correct 589 ms 832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 593 ms 1024 KB Output is correct
2 Correct 448 ms 1024 KB Output is correct
3 Correct 1101 ms 1016 KB Output is correct
4 Correct 764 ms 884 KB Output is correct
5 Correct 621 ms 1032 KB Output is correct
6 Correct 566 ms 1024 KB Output is correct
7 Correct 441 ms 1024 KB Output is correct
8 Correct 3 ms 1032 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 780 KB Output is correct
11 Correct 700 ms 768 KB Output is correct
12 Correct 516 ms 1024 KB Output is correct
13 Correct 496 ms 1108 KB Output is correct
14 Correct 489 ms 768 KB Output is correct
15 Correct 57 ms 868 KB Output is correct
16 Correct 63 ms 768 KB Output is correct
17 Correct 111 ms 768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 952 ms 868 KB Output is correct
2 Correct 658 ms 896 KB Output is correct
3 Correct 620 ms 1024 KB Output is correct
4 Correct 3 ms 872 KB Output is correct
5 Correct 5 ms 768 KB Output is correct
6 Correct 1 ms 872 KB Output is correct
7 Correct 667 ms 868 KB Output is correct
8 Correct 1033 ms 872 KB Output is correct
9 Correct 713 ms 872 KB Output is correct
10 Correct 738 ms 872 KB Output is correct
11 Correct 7 ms 872 KB Output is correct
12 Correct 6 ms 1024 KB Output is correct
13 Correct 6 ms 880 KB Output is correct
14 Correct 5 ms 768 KB Output is correct
15 Correct 2 ms 868 KB Output is correct
16 Correct 501 ms 996 KB Output is correct
17 Correct 534 ms 864 KB Output is correct
18 Correct 585 ms 876 KB Output is correct
19 Correct 581 ms 868 KB Output is correct
20 Correct 539 ms 868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 621 ms 1296 KB Output is correct
2 Correct 525 ms 1024 KB Output is correct
3 Correct 952 ms 868 KB Output is correct
4 Correct 646 ms 1168 KB Output is correct
5 Correct 628 ms 768 KB Output is correct
6 Correct 486 ms 1024 KB Output is correct
7 Correct 489 ms 776 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 2 ms 864 KB Output is correct
11 Correct 517 ms 812 KB Output is correct
12 Correct 545 ms 768 KB Output is correct
13 Correct 1014 ms 768 KB Output is correct
14 Correct 642 ms 872 KB Output is correct
15 Correct 634 ms 768 KB Output is correct
16 Correct 494 ms 820 KB Output is correct
17 Correct 630 ms 768 KB Output is correct
18 Correct 493 ms 768 KB Output is correct
19 Correct 544 ms 1280 KB Output is correct
20 Correct 555 ms 828 KB Output is correct
21 Correct 56 ms 864 KB Output is correct
22 Correct 68 ms 828 KB Output is correct
23 Correct 115 ms 808 KB Output is correct
24 Correct 7 ms 864 KB Output is correct
25 Correct 7 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 4 ms 872 KB Output is correct
28 Correct 1 ms 864 KB Output is correct
29 Correct 662 ms 1024 KB Output is correct
30 Correct 520 ms 868 KB Output is correct
31 Correct 523 ms 768 KB Output is correct
32 Correct 553 ms 768 KB Output is correct
33 Correct 580 ms 992 KB Output is correct
34 Correct 381 ms 1024 KB Output is correct
35 Correct 498 ms 1024 KB Output is correct
36 Correct 480 ms 1024 KB Output is correct
37 Correct 584 ms 896 KB Output is correct
38 Correct 497 ms 804 KB Output is correct
39 Correct 499 ms 1024 KB Output is correct
40 Correct 496 ms 1012 KB Output is correct
41 Correct 532 ms 900 KB Output is correct
42 Correct 66 ms 768 KB Output is correct
43 Correct 115 ms 800 KB Output is correct
44 Correct 133 ms 920 KB Output is correct
45 Correct 188 ms 1024 KB Output is correct
46 Correct 367 ms 812 KB Output is correct
47 Correct 408 ms 904 KB Output is correct
48 Correct 84 ms 768 KB Output is correct
49 Correct 76 ms 1136 KB Output is correct