답안 #316204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
316204 2020-10-25T17:02:18 Z ScarletS 기지국 (IOI20_stations) C++17
100 / 100
1059 ms 1280 KB
#include <bits/stdc++.h>
#define pii pair<int,int>
#define f first
#define s second
using namespace std;

const int maxn = 1e3;
int tin[maxn],tout[maxn],t;
vector<int> edges[maxn];
vector<pii> temp;

void dfs(int c, int p, bool h)
{
    tin[c]=++t;
    for (int i : edges[c])
        if (i!=p)
            dfs(i,c,h^1);
    tout[c]=++t;
    if (h)
        temp.push_back({tout[c],c});
    else
        temp.push_back({tin[c],c});
}

vector<int> label(int n, int k, vector<int> u, vector<int> v)
{
    vector<int> labels(n);
    for (int i=0;i<n;++i)
        edges[i].clear();
    for (int i=0;i<n-1;++i)
    {
        edges[u[i]].push_back(v[i]);
        edges[v[i]].push_back(u[i]);
    }
    temp.clear();
    t=-1;
    dfs(0,-1,0);
    sort(temp.begin(), temp.end());
    for (int i=0;i<n;++i)
        labels[temp[i].s]=i;
    return labels;
}

int find_next_station(int a, int b, vector<int> c)
{
    int x = c.size();
    sort(c.begin(), c.end());
    if (a==0)
    {
        if (1<=b&&b<=c[0])
            return c[0];
        for (int i=1;i<x;++i)
            if (c[i-1]+1<=b&&b<=c[i])
                return c[i];
    }
    if (a<c[0])
    {
        if (x>1)
        {
            if (a+1<=b&&b<=c[0])
                return c[0];
            for (int i=1;i<x-1;++i)
                if (c[i-1]+1<=b&&b<=c[i])
                    return c[i];
        }
        return c.back();
    }
    if (x>1)
    {
        if (c[x-1]<=b&&b<=a-1)
            return c[x-1];
        for (int i=x-2;i>=0;--i)
            if (c[i]<=b&&b<=c[i+1]-1)
                return c[i];
    }
    return c[0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 542 ms 1024 KB Output is correct
2 Correct 498 ms 1024 KB Output is correct
3 Correct 886 ms 876 KB Output is correct
4 Correct 755 ms 872 KB Output is correct
5 Correct 580 ms 872 KB Output is correct
6 Correct 484 ms 1112 KB Output is correct
7 Correct 497 ms 1024 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 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 539 ms 800 KB Output is correct
2 Correct 588 ms 932 KB Output is correct
3 Correct 944 ms 872 KB Output is correct
4 Correct 714 ms 768 KB Output is correct
5 Correct 662 ms 1008 KB Output is correct
6 Correct 532 ms 812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 617 ms 1128 KB Output is correct
2 Correct 462 ms 1024 KB Output is correct
3 Correct 1059 ms 1016 KB Output is correct
4 Correct 774 ms 1040 KB Output is correct
5 Correct 685 ms 876 KB Output is correct
6 Correct 532 ms 1008 KB Output is correct
7 Correct 489 ms 1024 KB Output is correct
8 Correct 3 ms 880 KB Output is correct
9 Correct 4 ms 768 KB Output is correct
10 Correct 1 ms 768 KB Output is correct
11 Correct 663 ms 768 KB Output is correct
12 Correct 487 ms 1024 KB Output is correct
13 Correct 567 ms 1024 KB Output is correct
14 Correct 551 ms 808 KB Output is correct
15 Correct 56 ms 768 KB Output is correct
16 Correct 86 ms 832 KB Output is correct
17 Correct 113 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1055 ms 1008 KB Output is correct
2 Correct 822 ms 768 KB Output is correct
3 Correct 679 ms 872 KB Output is correct
4 Correct 3 ms 876 KB Output is correct
5 Correct 5 ms 876 KB Output is correct
6 Correct 1 ms 884 KB Output is correct
7 Correct 576 ms 768 KB Output is correct
8 Correct 904 ms 876 KB Output is correct
9 Correct 718 ms 872 KB Output is correct
10 Correct 676 ms 872 KB Output is correct
11 Correct 6 ms 884 KB Output is correct
12 Correct 6 ms 872 KB Output is correct
13 Correct 5 ms 1000 KB Output is correct
14 Correct 4 ms 1024 KB Output is correct
15 Correct 2 ms 872 KB Output is correct
16 Correct 528 ms 768 KB Output is correct
17 Correct 551 ms 868 KB Output is correct
18 Correct 574 ms 768 KB Output is correct
19 Correct 517 ms 872 KB Output is correct
20 Correct 592 ms 872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 574 ms 1104 KB Output is correct
2 Correct 599 ms 1024 KB Output is correct
3 Correct 933 ms 768 KB Output is correct
4 Correct 646 ms 872 KB Output is correct
5 Correct 604 ms 876 KB Output is correct
6 Correct 465 ms 1280 KB Output is correct
7 Correct 465 ms 1024 KB Output is correct
8 Correct 3 ms 768 KB Output is correct
9 Correct 5 ms 768 KB Output is correct
10 Correct 2 ms 868 KB Output is correct
11 Correct 468 ms 768 KB Output is correct
12 Correct 543 ms 768 KB Output is correct
13 Correct 864 ms 1024 KB Output is correct
14 Correct 682 ms 768 KB Output is correct
15 Correct 600 ms 768 KB Output is correct
16 Correct 539 ms 1024 KB Output is correct
17 Correct 666 ms 768 KB Output is correct
18 Correct 486 ms 1016 KB Output is correct
19 Correct 503 ms 1024 KB Output is correct
20 Correct 427 ms 804 KB Output is correct
21 Correct 52 ms 868 KB Output is correct
22 Correct 96 ms 824 KB Output is correct
23 Correct 122 ms 812 KB Output is correct
24 Correct 6 ms 884 KB Output is correct
25 Correct 5 ms 768 KB Output is correct
26 Correct 6 ms 768 KB Output is correct
27 Correct 4 ms 880 KB Output is correct
28 Correct 2 ms 876 KB Output is correct
29 Correct 554 ms 768 KB Output is correct
30 Correct 539 ms 872 KB Output is correct
31 Correct 650 ms 880 KB Output is correct
32 Correct 508 ms 776 KB Output is correct
33 Correct 561 ms 768 KB Output is correct
34 Correct 330 ms 1024 KB Output is correct
35 Correct 577 ms 1280 KB Output is correct
36 Correct 560 ms 1092 KB Output is correct
37 Correct 526 ms 768 KB Output is correct
38 Correct 472 ms 888 KB Output is correct
39 Correct 544 ms 1016 KB Output is correct
40 Correct 532 ms 1024 KB Output is correct
41 Correct 456 ms 892 KB Output is correct
42 Correct 66 ms 812 KB Output is correct
43 Correct 109 ms 800 KB Output is correct
44 Correct 130 ms 784 KB Output is correct
45 Correct 177 ms 768 KB Output is correct
46 Correct 299 ms 768 KB Output is correct
47 Correct 305 ms 768 KB Output is correct
48 Correct 66 ms 1024 KB Output is correct
49 Correct 66 ms 1024 KB Output is correct