Submission #245459

# Submission time Handle Problem Language Result Execution time Memory
245459 2020-07-06T13:28:57 Z gratus907 Dreaming (IOI13_dreaming) C++17
47 / 100
1000 ms 15492 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define ll long long
#define all(x) ((x).begin()),((x).end())
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using pii=pair<int, int>;
vector <pii> Graph[101010];
int n, m;
bool vst[101010];
bool dfs_visit[101010];
vector <pii> radii; 
vector <int> cur_tree;
pii dist_bfs(vector <int> &par, vector<int> &dt, int root, vector<int> &Tr)
{
    vector <bool> tmpvisit(101010, false);
    queue <int> q;
    q.push(root);
    dt[root] = 0;
    par[root] = -1;
    tmpvisit[root] = true;
    while(!q.empty())
    {
        int x = q.front();
        q.pop();
        for (auto it:Graph[x])
        {
            if (!tmpvisit[it.first])
            {
                dt[it.first] = dt[x]+it.second;
                tmpvisit[it.first] = true;
                q.push(it.first);
                par[it.first] = x;
            }
        }
    }
    int maxdist = 0, maxdistpoint = 0;
    for (auto nd : Tr)
    {
        if (dt[nd] >= maxdist)
        {
            maxdist = dt[nd];
            maxdistpoint = nd;
        }
    }
    return {maxdist, maxdistpoint};
}

void dfs(int r, int p)
{
    cur_tree.push_back(r);
    dfs_visit[r] = true;
    for (auto it:Graph[r])
    {
        if (!dfs_visit[it.first])
        {
            if (it.first != p)
            {
                dfs(it.first, r);
            }
        }
    }
}
pii decomp_tree(int root)
{
    vector<int> dt(101010, 1e8);
    vector<int> par(101010, 0);
    pii p1 = dist_bfs(par, dt, root, cur_tree);
    par.clear();
    par.resize(101010, 0);
    dt.clear();
    dt.resize(101010, 1e8);
    pii p2 = dist_bfs(par, dt, p1.second, cur_tree);
    int A = p1.second, B = p2.second;
    int p = B;
    vector <int> TT; 
    while(p!=-1)
    {
        TT.push_back(p);
        p = par[p];
    }
    vector <int> RR;
    int R = INT_MAX;
    for (auto it:TT)
        R = min(R, max(dt[it], dt[B]-dt[it]));
    return {R, dt[B]};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) 
{
    n = N, m = M;
    for (int i = 0; i<M; i++)
    {
        Graph[A[i]].push_back({B[i],T[i]});
        Graph[B[i]].push_back({A[i],T[i]});
    }
    for (int i = 0; i<N; i++)
    {
        if (vst[i]) continue;
        memset(dfs_visit, 0, sizeof(dfs_visit));
        cur_tree.clear();
        dfs(i, -1);
        for (auto it:cur_tree)
            vst[it] = true;
        radii.push_back(decomp_tree(i));
    }
//    for (auto it:radii)
//        printf("%d %d\n",it.first, it.second);
    sort(all(radii),greater<pii>());
    if (radii.size()==1)
        return radii.front().second;
    else
    {

        int cand_1 = radii[0].first+radii[1].first+L;
        int cand_2 = 0;
        for (auto it:radii)
            cand_2 = max(cand_2, it.second);
        int cand_3 = 0;
        if (radii.size()>2)
        {
            cand_3 = radii[1].first+radii[2].first+2*L;
        }
        return max(max(cand_1, cand_2),cand_3);
    }
}

Compilation message

dreaming.cpp: In function 'pii decomp_tree(int)':
dreaming.cpp:74:9: warning: unused variable 'A' [-Wunused-variable]
     int A = p1.second, B = p2.second;
         ^
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11636 KB Output is correct
2 Correct 64 ms 12148 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 16 ms 4864 KB Output is correct
5 Correct 14 ms 4352 KB Output is correct
6 Correct 21 ms 5632 KB Output is correct
7 Correct 8 ms 3712 KB Output is correct
8 Correct 34 ms 7112 KB Output is correct
9 Correct 51 ms 8952 KB Output is correct
10 Correct 7 ms 3712 KB Output is correct
11 Correct 80 ms 9976 KB Output is correct
12 Correct 79 ms 11248 KB Output is correct
13 Correct 7 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11636 KB Output is correct
2 Correct 64 ms 12148 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 16 ms 4864 KB Output is correct
5 Correct 14 ms 4352 KB Output is correct
6 Correct 21 ms 5632 KB Output is correct
7 Correct 8 ms 3712 KB Output is correct
8 Correct 34 ms 7112 KB Output is correct
9 Correct 51 ms 8952 KB Output is correct
10 Correct 7 ms 3712 KB Output is correct
11 Correct 80 ms 9976 KB Output is correct
12 Correct 79 ms 11248 KB Output is correct
13 Correct 7 ms 3712 KB Output is correct
14 Correct 7 ms 3584 KB Output is correct
15 Correct 7 ms 3584 KB Output is correct
16 Correct 7 ms 3584 KB Output is correct
17 Correct 7 ms 3584 KB Output is correct
18 Correct 8 ms 3584 KB Output is correct
19 Correct 8 ms 3584 KB Output is correct
20 Correct 8 ms 3712 KB Output is correct
21 Correct 7 ms 3584 KB Output is correct
22 Correct 7 ms 3584 KB Output is correct
23 Correct 7 ms 3584 KB Output is correct
24 Correct 7 ms 3712 KB Output is correct
25 Correct 7 ms 3712 KB Output is correct
26 Correct 7 ms 3584 KB Output is correct
27 Correct 7 ms 3584 KB Output is correct
28 Correct 7 ms 3688 KB Output is correct
29 Correct 9 ms 3712 KB Output is correct
30 Correct 7 ms 3712 KB Output is correct
31 Correct 7 ms 3584 KB Output is correct
32 Correct 7 ms 3712 KB Output is correct
33 Correct 10 ms 3688 KB Output is correct
34 Correct 8 ms 3688 KB Output is correct
35 Correct 8 ms 3688 KB Output is correct
36 Correct 7 ms 3584 KB Output is correct
37 Correct 7 ms 3584 KB Output is correct
38 Correct 8 ms 3688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11636 KB Output is correct
2 Correct 64 ms 12148 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 16 ms 4864 KB Output is correct
5 Correct 14 ms 4352 KB Output is correct
6 Correct 21 ms 5632 KB Output is correct
7 Correct 8 ms 3712 KB Output is correct
8 Correct 34 ms 7112 KB Output is correct
9 Correct 51 ms 8952 KB Output is correct
10 Correct 7 ms 3712 KB Output is correct
11 Correct 80 ms 9976 KB Output is correct
12 Correct 79 ms 11248 KB Output is correct
13 Correct 7 ms 3712 KB Output is correct
14 Correct 7 ms 3584 KB Output is correct
15 Correct 7 ms 3584 KB Output is correct
16 Correct 7 ms 3584 KB Output is correct
17 Correct 7 ms 3584 KB Output is correct
18 Correct 8 ms 3584 KB Output is correct
19 Correct 8 ms 3584 KB Output is correct
20 Correct 8 ms 3712 KB Output is correct
21 Correct 7 ms 3584 KB Output is correct
22 Correct 7 ms 3584 KB Output is correct
23 Correct 7 ms 3584 KB Output is correct
24 Correct 7 ms 3712 KB Output is correct
25 Correct 7 ms 3712 KB Output is correct
26 Correct 7 ms 3584 KB Output is correct
27 Correct 7 ms 3584 KB Output is correct
28 Correct 7 ms 3688 KB Output is correct
29 Correct 9 ms 3712 KB Output is correct
30 Correct 7 ms 3712 KB Output is correct
31 Correct 7 ms 3584 KB Output is correct
32 Correct 7 ms 3712 KB Output is correct
33 Correct 10 ms 3688 KB Output is correct
34 Correct 8 ms 3688 KB Output is correct
35 Correct 8 ms 3688 KB Output is correct
36 Correct 7 ms 3584 KB Output is correct
37 Correct 7 ms 3584 KB Output is correct
38 Correct 8 ms 3688 KB Output is correct
39 Correct 65 ms 12404 KB Output is correct
40 Correct 73 ms 12148 KB Output is correct
41 Correct 46 ms 10356 KB Output is correct
42 Correct 15 ms 4864 KB Output is correct
43 Correct 7 ms 3584 KB Output is correct
44 Correct 7 ms 3584 KB Output is correct
45 Correct 8 ms 3584 KB Output is correct
46 Correct 8 ms 3584 KB Output is correct
47 Correct 7 ms 3688 KB Output is correct
48 Correct 7 ms 3584 KB Output is correct
49 Correct 8 ms 3688 KB Output is correct
50 Correct 7 ms 3584 KB Output is correct
51 Correct 7 ms 3584 KB Output is correct
52 Correct 7 ms 3584 KB Output is correct
53 Correct 7 ms 3584 KB Output is correct
54 Correct 7 ms 3584 KB Output is correct
55 Correct 7 ms 3584 KB Output is correct
56 Correct 7 ms 3688 KB Output is correct
57 Correct 99 ms 10608 KB Output is correct
58 Correct 95 ms 10484 KB Output is correct
59 Correct 105 ms 10740 KB Output is correct
60 Correct 122 ms 10484 KB Output is correct
61 Correct 143 ms 10736 KB Output is correct
62 Correct 110 ms 10488 KB Output is correct
63 Correct 87 ms 10484 KB Output is correct
64 Correct 95 ms 10356 KB Output is correct
65 Correct 96 ms 10740 KB Output is correct
66 Correct 93 ms 10740 KB Output is correct
67 Correct 112 ms 10608 KB Output is correct
68 Correct 95 ms 10608 KB Output is correct
69 Correct 102 ms 10612 KB Output is correct
70 Correct 101 ms 10740 KB Output is correct
71 Correct 8 ms 3688 KB Output is correct
72 Correct 9 ms 3840 KB Output is correct
73 Correct 9 ms 3944 KB Output is correct
74 Correct 9 ms 3840 KB Output is correct
75 Correct 10 ms 3840 KB Output is correct
76 Correct 9 ms 3840 KB Output is correct
77 Correct 9 ms 3840 KB Output is correct
78 Correct 9 ms 3840 KB Output is correct
79 Correct 9 ms 3840 KB Output is correct
80 Correct 105 ms 10460 KB Output is correct
81 Correct 138 ms 10480 KB Output is correct
82 Correct 120 ms 10716 KB Output is correct
83 Correct 99 ms 10736 KB Output is correct
84 Correct 10 ms 3840 KB Output is correct
85 Correct 9 ms 3816 KB Output is correct
86 Correct 9 ms 3840 KB Output is correct
87 Correct 11 ms 3840 KB Output is correct
88 Correct 9 ms 3840 KB Output is correct
89 Correct 8 ms 3840 KB Output is correct
90 Correct 10 ms 3840 KB Output is correct
91 Correct 9 ms 3840 KB Output is correct
92 Correct 9 ms 3840 KB Output is correct
93 Correct 9 ms 3840 KB Output is correct
94 Correct 8 ms 3688 KB Output is correct
95 Correct 7 ms 3584 KB Output is correct
96 Correct 7 ms 3584 KB Output is correct
97 Correct 7 ms 3712 KB Output is correct
98 Correct 7 ms 3688 KB Output is correct
99 Correct 7 ms 3584 KB Output is correct
100 Correct 9 ms 3584 KB Output is correct
101 Correct 7 ms 3584 KB Output is correct
102 Correct 7 ms 3712 KB Output is correct
103 Correct 8 ms 3584 KB Output is correct
104 Correct 13 ms 4456 KB Output is correct
105 Correct 22 ms 5632 KB Output is correct
106 Correct 9 ms 3688 KB Output is correct
107 Correct 35 ms 7136 KB Output is correct
108 Correct 43 ms 8824 KB Output is correct
109 Correct 7 ms 3712 KB Output is correct
110 Correct 67 ms 10104 KB Output is correct
111 Correct 72 ms 11248 KB Output is correct
112 Correct 7 ms 3712 KB Output is correct
113 Correct 108 ms 15492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1095 ms 6704 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11636 KB Output is correct
2 Correct 64 ms 12148 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 16 ms 4864 KB Output is correct
5 Correct 14 ms 4352 KB Output is correct
6 Correct 21 ms 5632 KB Output is correct
7 Correct 8 ms 3712 KB Output is correct
8 Correct 34 ms 7112 KB Output is correct
9 Correct 51 ms 8952 KB Output is correct
10 Correct 7 ms 3712 KB Output is correct
11 Correct 80 ms 9976 KB Output is correct
12 Correct 79 ms 11248 KB Output is correct
13 Correct 7 ms 3712 KB Output is correct
14 Correct 70 ms 3728 KB Output is correct
15 Correct 135 ms 3800 KB Output is correct
16 Correct 192 ms 3932 KB Output is correct
17 Correct 68 ms 4068 KB Output is correct
18 Correct 122 ms 3780 KB Output is correct
19 Correct 181 ms 3872 KB Output is correct
20 Correct 69 ms 3936 KB Output is correct
21 Correct 114 ms 4124 KB Output is correct
22 Correct 152 ms 3848 KB Output is correct
23 Correct 7 ms 3652 KB Output is correct
24 Correct 7 ms 3584 KB Output is correct
25 Correct 7 ms 3584 KB Output is correct
26 Correct 10 ms 3584 KB Output is correct
27 Correct 7 ms 3688 KB Output is correct
28 Correct 44 ms 3740 KB Output is correct
29 Correct 33 ms 3732 KB Output is correct
30 Correct 7 ms 3584 KB Output is correct
31 Correct 8 ms 3688 KB Output is correct
32 Correct 7 ms 3688 KB Output is correct
33 Correct 7 ms 3584 KB Output is correct
34 Correct 7 ms 3584 KB Output is correct
35 Correct 8 ms 3688 KB Output is correct
36 Correct 7 ms 3584 KB Output is correct
37 Correct 7 ms 3584 KB Output is correct
38 Correct 9 ms 3664 KB Output is correct
39 Correct 7 ms 3584 KB Output is correct
40 Correct 7 ms 3584 KB Output is correct
41 Correct 8 ms 3688 KB Output is correct
42 Correct 9 ms 3968 KB Output is correct
43 Correct 10 ms 3944 KB Output is correct
44 Correct 564 ms 4036 KB Output is correct
45 Correct 976 ms 3876 KB Output is correct
46 Correct 9 ms 3840 KB Output is correct
47 Correct 11 ms 3840 KB Output is correct
48 Correct 672 ms 3860 KB Output is correct
49 Correct 830 ms 3768 KB Output is correct
50 Correct 10 ms 3840 KB Output is correct
51 Correct 9 ms 3840 KB Output is correct
52 Execution timed out 1084 ms 3812 KB Time limit exceeded
53 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 60 ms 11636 KB Output is correct
2 Correct 64 ms 12148 KB Output is correct
3 Correct 46 ms 10228 KB Output is correct
4 Correct 16 ms 4864 KB Output is correct
5 Correct 14 ms 4352 KB Output is correct
6 Correct 21 ms 5632 KB Output is correct
7 Correct 8 ms 3712 KB Output is correct
8 Correct 34 ms 7112 KB Output is correct
9 Correct 51 ms 8952 KB Output is correct
10 Correct 7 ms 3712 KB Output is correct
11 Correct 80 ms 9976 KB Output is correct
12 Correct 79 ms 11248 KB Output is correct
13 Correct 7 ms 3712 KB Output is correct
14 Correct 7 ms 3584 KB Output is correct
15 Correct 7 ms 3584 KB Output is correct
16 Correct 7 ms 3584 KB Output is correct
17 Correct 7 ms 3584 KB Output is correct
18 Correct 8 ms 3584 KB Output is correct
19 Correct 8 ms 3584 KB Output is correct
20 Correct 8 ms 3712 KB Output is correct
21 Correct 7 ms 3584 KB Output is correct
22 Correct 7 ms 3584 KB Output is correct
23 Correct 7 ms 3584 KB Output is correct
24 Correct 7 ms 3712 KB Output is correct
25 Correct 7 ms 3712 KB Output is correct
26 Correct 7 ms 3584 KB Output is correct
27 Correct 7 ms 3584 KB Output is correct
28 Correct 7 ms 3688 KB Output is correct
29 Correct 9 ms 3712 KB Output is correct
30 Correct 7 ms 3712 KB Output is correct
31 Correct 7 ms 3584 KB Output is correct
32 Correct 7 ms 3712 KB Output is correct
33 Correct 10 ms 3688 KB Output is correct
34 Correct 8 ms 3688 KB Output is correct
35 Correct 8 ms 3688 KB Output is correct
36 Correct 7 ms 3584 KB Output is correct
37 Correct 7 ms 3584 KB Output is correct
38 Correct 8 ms 3688 KB Output is correct
39 Correct 65 ms 12404 KB Output is correct
40 Correct 73 ms 12148 KB Output is correct
41 Correct 46 ms 10356 KB Output is correct
42 Correct 15 ms 4864 KB Output is correct
43 Correct 7 ms 3584 KB Output is correct
44 Correct 7 ms 3584 KB Output is correct
45 Correct 8 ms 3584 KB Output is correct
46 Correct 8 ms 3584 KB Output is correct
47 Correct 7 ms 3688 KB Output is correct
48 Correct 7 ms 3584 KB Output is correct
49 Correct 8 ms 3688 KB Output is correct
50 Correct 7 ms 3584 KB Output is correct
51 Correct 7 ms 3584 KB Output is correct
52 Correct 7 ms 3584 KB Output is correct
53 Correct 7 ms 3584 KB Output is correct
54 Correct 7 ms 3584 KB Output is correct
55 Correct 7 ms 3584 KB Output is correct
56 Correct 7 ms 3688 KB Output is correct
57 Correct 99 ms 10608 KB Output is correct
58 Correct 95 ms 10484 KB Output is correct
59 Correct 105 ms 10740 KB Output is correct
60 Correct 122 ms 10484 KB Output is correct
61 Correct 143 ms 10736 KB Output is correct
62 Correct 110 ms 10488 KB Output is correct
63 Correct 87 ms 10484 KB Output is correct
64 Correct 95 ms 10356 KB Output is correct
65 Correct 96 ms 10740 KB Output is correct
66 Correct 93 ms 10740 KB Output is correct
67 Correct 112 ms 10608 KB Output is correct
68 Correct 95 ms 10608 KB Output is correct
69 Correct 102 ms 10612 KB Output is correct
70 Correct 101 ms 10740 KB Output is correct
71 Correct 8 ms 3688 KB Output is correct
72 Correct 9 ms 3840 KB Output is correct
73 Correct 9 ms 3944 KB Output is correct
74 Correct 9 ms 3840 KB Output is correct
75 Correct 10 ms 3840 KB Output is correct
76 Correct 9 ms 3840 KB Output is correct
77 Correct 9 ms 3840 KB Output is correct
78 Correct 9 ms 3840 KB Output is correct
79 Correct 9 ms 3840 KB Output is correct
80 Correct 105 ms 10460 KB Output is correct
81 Correct 138 ms 10480 KB Output is correct
82 Correct 120 ms 10716 KB Output is correct
83 Correct 99 ms 10736 KB Output is correct
84 Correct 10 ms 3840 KB Output is correct
85 Correct 9 ms 3816 KB Output is correct
86 Correct 9 ms 3840 KB Output is correct
87 Correct 11 ms 3840 KB Output is correct
88 Correct 9 ms 3840 KB Output is correct
89 Correct 8 ms 3840 KB Output is correct
90 Correct 10 ms 3840 KB Output is correct
91 Correct 9 ms 3840 KB Output is correct
92 Correct 9 ms 3840 KB Output is correct
93 Correct 9 ms 3840 KB Output is correct
94 Correct 8 ms 3688 KB Output is correct
95 Correct 7 ms 3584 KB Output is correct
96 Correct 7 ms 3584 KB Output is correct
97 Correct 7 ms 3712 KB Output is correct
98 Correct 7 ms 3688 KB Output is correct
99 Correct 7 ms 3584 KB Output is correct
100 Correct 9 ms 3584 KB Output is correct
101 Correct 7 ms 3584 KB Output is correct
102 Correct 7 ms 3712 KB Output is correct
103 Correct 8 ms 3584 KB Output is correct
104 Correct 13 ms 4456 KB Output is correct
105 Correct 22 ms 5632 KB Output is correct
106 Correct 9 ms 3688 KB Output is correct
107 Correct 35 ms 7136 KB Output is correct
108 Correct 43 ms 8824 KB Output is correct
109 Correct 7 ms 3712 KB Output is correct
110 Correct 67 ms 10104 KB Output is correct
111 Correct 72 ms 11248 KB Output is correct
112 Correct 7 ms 3712 KB Output is correct
113 Correct 108 ms 15492 KB Output is correct
114 Execution timed out 1095 ms 6704 KB Time limit exceeded
115 Halted 0 ms 0 KB -