답안 #962066

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962066 2024-04-13T06:36:03 Z danikoynov 꿈 (IOI13_dreaming) C++14
47 / 100
75 ms 17084 KB
#include "dreaming.h"
#include<bits/stdc++.h>


using namespace std;
typedef long long ll;

const int maxn = 1e5 + 10;

vector < pair < int, int > > adj[maxn];

int used[maxn], depth[maxn];
int max_depth[maxn], sec[maxn];
void calc(int v, int p)
{
    max_depth[v] = 0;
    for (pair < int, int > nb : adj[v])
    {
        int u = nb.first;
        if (u == p)
            continue;
        depth[u] = depth[v] + nb.second;
        calc(u, v);
        int vl = max_depth[u] + nb.second;
        if (vl > max_depth[v])
        {
             sec[v] = max_depth[v];
             max_depth[v] = vl;
        }
        else
     if (vl > sec[v])
     {
          sec[v] = vl;
     }
        ///max_depth[v] = max(max_depth[v], max_depth[u] + nb.second);
    }
}
vector < int > ord;
void trav(int v, int p)
{
    ord.push_back(v);
    used[v] = 1;
    for (pair < int, int > nb : adj[v])
    {
        if (nb.first == p)
            continue;
        trav(nb.first, v);
    }
}

int dist;

void dfs(int v, int p, int lon)
{

    //cout << "dfs " << v << " " << p << " " << lon << endl;

    //cout << val << " " << sec << endl;
    dist = min(dist, max(lon, max_depth[v]));

    if (lon >= max_depth[v])
     return;

    for (pair < int, int > nb : adj[v])
    {
        int u = nb.first;
        if (u == p)
            continue;
        if (max_depth[u] + nb.second == max_depth[v])
        {
             dfs(u, v, max(lon, sec[v]) + nb.second);
             return;
        }
    }
}
int cap;

int path[maxn];
void bfs(int v)
{
    for (int w : ord)
        path[w] = -1;
    path[v] = 0;
    queue < int > q;
    q.push(v);
    while(!q.empty())
    {
        v = q.front();
        q.pop();
        for (pair <int, int > nb : adj[v])
        {
            if (path[nb.first] == -1)
            {
                path[nb.first] = path[v] + nb.second;
                q.push(nb.first);
            }
        }
    }
}
int find_distance(int v)
{
    ord.clear();
    trav(v, -1);
    dist = 2e9;
     calc(v, -1);
     dfs(v, -1, 0);

    /**for (int w : ord)
    {
        calc(w, -1);
        dist = min(dist, max_depth[w]);
    }*/
    bfs(v);
    int ds = v;
    for (int u : ord)
        if (path[u] > path[ds])
            ds = u;
    bfs(ds);
    for (int u : ord)
        if (path[u] > cap)
            cap = path[u];
    return dist;
}


int travelTime(int N, int M, int L, int A[], int B[], int T[])
{

    for (int i = 0; i < M; i ++)
    {
        adj[A[i]].push_back({B[i], T[i]});
        adj[B[i]].push_back({A[i], T[i]});
    }

    //cout << find_distance(1) << endl;
    //exit(0);
    vector < int > values;
    for (int i = 0; i < N; i ++)
    {
        if (!used[i])
            values.push_back(find_distance(i));
    }


    //for (int cur : values)
    //cout << cur << " ";
    //cout << endl;
    sort(values.begin(), values.end());

    int sz = values.size();
    int res = values[sz - 1] + values[sz - 2] + L;
    if (sz >= 3)
        res = max(res, values[sz - 2] + values[sz - 3] + 2 * L);
    res = max(res, cap);
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 13008 KB Output is correct
2 Correct 41 ms 13008 KB Output is correct
3 Correct 30 ms 12336 KB Output is correct
4 Correct 6 ms 6748 KB Output is correct
5 Correct 5 ms 6232 KB Output is correct
6 Correct 10 ms 7516 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 22 ms 9040 KB Output is correct
9 Correct 25 ms 10716 KB Output is correct
10 Correct 1 ms 5720 KB Output is correct
11 Correct 33 ms 10964 KB Output is correct
12 Correct 38 ms 11996 KB Output is correct
13 Correct 2 ms 5720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 1 ms 5720 KB Output is correct
8 Correct 1 ms 5720 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5732 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 1 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 1 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 13008 KB Output is correct
2 Correct 41 ms 13008 KB Output is correct
3 Correct 30 ms 12336 KB Output is correct
4 Correct 6 ms 6748 KB Output is correct
5 Correct 5 ms 6232 KB Output is correct
6 Correct 10 ms 7516 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 22 ms 9040 KB Output is correct
9 Correct 25 ms 10716 KB Output is correct
10 Correct 1 ms 5720 KB Output is correct
11 Correct 33 ms 10964 KB Output is correct
12 Correct 38 ms 11996 KB Output is correct
13 Correct 2 ms 5720 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 1 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5720 KB Output is correct
21 Correct 1 ms 5720 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 1 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5732 KB Output is correct
29 Correct 2 ms 5724 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 1 ms 5724 KB Output is correct
32 Correct 1 ms 5724 KB Output is correct
33 Correct 1 ms 5724 KB Output is correct
34 Correct 1 ms 5724 KB Output is correct
35 Correct 1 ms 5724 KB Output is correct
36 Correct 1 ms 5724 KB Output is correct
37 Correct 1 ms 5724 KB Output is correct
38 Correct 1 ms 5724 KB Output is correct
39 Correct 42 ms 13284 KB Output is correct
40 Correct 42 ms 13076 KB Output is correct
41 Correct 31 ms 12440 KB Output is correct
42 Correct 6 ms 6744 KB Output is correct
43 Correct 1 ms 5724 KB Output is correct
44 Correct 2 ms 5724 KB Output is correct
45 Correct 1 ms 5724 KB Output is correct
46 Correct 1 ms 5724 KB Output is correct
47 Correct 2 ms 5724 KB Output is correct
48 Correct 2 ms 5724 KB Output is correct
49 Correct 2 ms 5724 KB Output is correct
50 Correct 1 ms 5724 KB Output is correct
51 Correct 2 ms 5724 KB Output is correct
52 Correct 2 ms 5724 KB Output is correct
53 Correct 1 ms 5724 KB Output is correct
54 Correct 1 ms 5724 KB Output is correct
55 Correct 1 ms 5724 KB Output is correct
56 Correct 1 ms 5720 KB Output is correct
57 Correct 63 ms 10916 KB Output is correct
58 Correct 51 ms 10464 KB Output is correct
59 Correct 44 ms 10704 KB Output is correct
60 Correct 47 ms 10468 KB Output is correct
61 Correct 50 ms 10716 KB Output is correct
62 Correct 47 ms 10428 KB Output is correct
63 Correct 42 ms 10568 KB Output is correct
64 Correct 42 ms 10276 KB Output is correct
65 Correct 43 ms 10700 KB Output is correct
66 Correct 52 ms 10616 KB Output is correct
67 Correct 51 ms 10604 KB Output is correct
68 Correct 51 ms 10668 KB Output is correct
69 Correct 50 ms 10676 KB Output is correct
70 Correct 54 ms 10416 KB Output is correct
71 Correct 2 ms 5720 KB Output is correct
72 Correct 2 ms 5760 KB Output is correct
73 Correct 4 ms 5724 KB Output is correct
74 Correct 2 ms 5720 KB Output is correct
75 Correct 3 ms 5724 KB Output is correct
76 Correct 3 ms 5720 KB Output is correct
77 Correct 2 ms 5724 KB Output is correct
78 Correct 2 ms 5724 KB Output is correct
79 Correct 3 ms 5724 KB Output is correct
80 Correct 58 ms 10984 KB Output is correct
81 Correct 75 ms 10704 KB Output is correct
82 Correct 51 ms 10632 KB Output is correct
83 Correct 47 ms 10408 KB Output is correct
84 Correct 2 ms 5724 KB Output is correct
85 Correct 2 ms 5724 KB Output is correct
86 Correct 2 ms 5724 KB Output is correct
87 Correct 3 ms 5724 KB Output is correct
88 Correct 2 ms 5724 KB Output is correct
89 Correct 2 ms 5724 KB Output is correct
90 Correct 2 ms 5724 KB Output is correct
91 Correct 2 ms 5724 KB Output is correct
92 Correct 3 ms 5724 KB Output is correct
93 Correct 3 ms 5720 KB Output is correct
94 Correct 1 ms 5724 KB Output is correct
95 Correct 2 ms 5724 KB Output is correct
96 Correct 2 ms 5720 KB Output is correct
97 Correct 2 ms 5724 KB Output is correct
98 Correct 1 ms 5724 KB Output is correct
99 Correct 1 ms 5720 KB Output is correct
100 Correct 1 ms 5724 KB Output is correct
101 Correct 1 ms 5724 KB Output is correct
102 Correct 1 ms 5720 KB Output is correct
103 Correct 1 ms 5720 KB Output is correct
104 Correct 5 ms 6236 KB Output is correct
105 Correct 10 ms 7516 KB Output is correct
106 Correct 2 ms 5724 KB Output is correct
107 Correct 19 ms 8676 KB Output is correct
108 Correct 27 ms 10716 KB Output is correct
109 Correct 2 ms 5724 KB Output is correct
110 Correct 35 ms 11004 KB Output is correct
111 Correct 47 ms 11996 KB Output is correct
112 Correct 2 ms 5720 KB Output is correct
113 Correct 55 ms 17084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 8100 KB Output is correct
2 Correct 28 ms 8156 KB Output is correct
3 Correct 18 ms 8152 KB Output is correct
4 Correct 21 ms 8156 KB Output is correct
5 Correct 18 ms 8156 KB Output is correct
6 Correct 19 ms 8508 KB Output is correct
7 Correct 20 ms 8208 KB Output is correct
8 Correct 19 ms 8148 KB Output is correct
9 Correct 25 ms 8028 KB Output is correct
10 Correct 22 ms 8284 KB Output is correct
11 Correct 2 ms 5720 KB Output is correct
12 Correct 10 ms 6360 KB Output is correct
13 Correct 10 ms 6356 KB Output is correct
14 Correct 10 ms 6360 KB Output is correct
15 Correct 10 ms 6612 KB Output is correct
16 Correct 10 ms 6268 KB Output is correct
17 Correct 10 ms 6360 KB Output is correct
18 Correct 12 ms 6356 KB Output is correct
19 Correct 10 ms 6360 KB Output is correct
20 Incorrect 1 ms 5724 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 2 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 1 ms 5720 KB Output is correct
8 Correct 1 ms 5720 KB Output is correct
9 Correct 2 ms 5724 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 2 ms 5724 KB Output is correct
12 Correct 1 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5732 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5724 KB Output is correct
18 Correct 1 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 1 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 1 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 2 ms 5724 KB Output is correct
27 Correct 2 ms 5744 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 2 ms 5724 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 2 ms 5724 KB Output is correct
32 Correct 2 ms 5724 KB Output is correct
33 Correct 2 ms 5724 KB Output is correct
34 Correct 2 ms 5724 KB Output is correct
35 Correct 1 ms 5724 KB Output is correct
36 Correct 2 ms 5724 KB Output is correct
37 Correct 1 ms 5736 KB Output is correct
38 Correct 2 ms 5724 KB Output is correct
39 Correct 1 ms 5724 KB Output is correct
40 Correct 2 ms 5724 KB Output is correct
41 Correct 2 ms 5724 KB Output is correct
42 Correct 1 ms 5724 KB Output is correct
43 Correct 1 ms 5724 KB Output is correct
44 Correct 3 ms 5720 KB Output is correct
45 Correct 1 ms 5724 KB Output is correct
46 Correct 2 ms 5724 KB Output is correct
47 Correct 1 ms 5720 KB Output is correct
48 Correct 1 ms 5720 KB Output is correct
49 Correct 1 ms 5724 KB Output is correct
50 Correct 1 ms 5720 KB Output is correct
51 Correct 1 ms 5724 KB Output is correct
52 Incorrect 1 ms 5724 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 13008 KB Output is correct
2 Correct 41 ms 13008 KB Output is correct
3 Correct 30 ms 12336 KB Output is correct
4 Correct 6 ms 6748 KB Output is correct
5 Correct 5 ms 6232 KB Output is correct
6 Correct 10 ms 7516 KB Output is correct
7 Correct 1 ms 5724 KB Output is correct
8 Correct 22 ms 9040 KB Output is correct
9 Correct 25 ms 10716 KB Output is correct
10 Correct 1 ms 5720 KB Output is correct
11 Correct 33 ms 10964 KB Output is correct
12 Correct 38 ms 11996 KB Output is correct
13 Correct 2 ms 5720 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 1 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5720 KB Output is correct
21 Correct 1 ms 5720 KB Output is correct
22 Correct 2 ms 5724 KB Output is correct
23 Correct 1 ms 5724 KB Output is correct
24 Correct 2 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5732 KB Output is correct
29 Correct 2 ms 5724 KB Output is correct
30 Correct 2 ms 5724 KB Output is correct
31 Correct 1 ms 5724 KB Output is correct
32 Correct 1 ms 5724 KB Output is correct
33 Correct 1 ms 5724 KB Output is correct
34 Correct 1 ms 5724 KB Output is correct
35 Correct 1 ms 5724 KB Output is correct
36 Correct 1 ms 5724 KB Output is correct
37 Correct 1 ms 5724 KB Output is correct
38 Correct 1 ms 5724 KB Output is correct
39 Correct 42 ms 13284 KB Output is correct
40 Correct 42 ms 13076 KB Output is correct
41 Correct 31 ms 12440 KB Output is correct
42 Correct 6 ms 6744 KB Output is correct
43 Correct 1 ms 5724 KB Output is correct
44 Correct 2 ms 5724 KB Output is correct
45 Correct 1 ms 5724 KB Output is correct
46 Correct 1 ms 5724 KB Output is correct
47 Correct 2 ms 5724 KB Output is correct
48 Correct 2 ms 5724 KB Output is correct
49 Correct 2 ms 5724 KB Output is correct
50 Correct 1 ms 5724 KB Output is correct
51 Correct 2 ms 5724 KB Output is correct
52 Correct 2 ms 5724 KB Output is correct
53 Correct 1 ms 5724 KB Output is correct
54 Correct 1 ms 5724 KB Output is correct
55 Correct 1 ms 5724 KB Output is correct
56 Correct 1 ms 5720 KB Output is correct
57 Correct 63 ms 10916 KB Output is correct
58 Correct 51 ms 10464 KB Output is correct
59 Correct 44 ms 10704 KB Output is correct
60 Correct 47 ms 10468 KB Output is correct
61 Correct 50 ms 10716 KB Output is correct
62 Correct 47 ms 10428 KB Output is correct
63 Correct 42 ms 10568 KB Output is correct
64 Correct 42 ms 10276 KB Output is correct
65 Correct 43 ms 10700 KB Output is correct
66 Correct 52 ms 10616 KB Output is correct
67 Correct 51 ms 10604 KB Output is correct
68 Correct 51 ms 10668 KB Output is correct
69 Correct 50 ms 10676 KB Output is correct
70 Correct 54 ms 10416 KB Output is correct
71 Correct 2 ms 5720 KB Output is correct
72 Correct 2 ms 5760 KB Output is correct
73 Correct 4 ms 5724 KB Output is correct
74 Correct 2 ms 5720 KB Output is correct
75 Correct 3 ms 5724 KB Output is correct
76 Correct 3 ms 5720 KB Output is correct
77 Correct 2 ms 5724 KB Output is correct
78 Correct 2 ms 5724 KB Output is correct
79 Correct 3 ms 5724 KB Output is correct
80 Correct 58 ms 10984 KB Output is correct
81 Correct 75 ms 10704 KB Output is correct
82 Correct 51 ms 10632 KB Output is correct
83 Correct 47 ms 10408 KB Output is correct
84 Correct 2 ms 5724 KB Output is correct
85 Correct 2 ms 5724 KB Output is correct
86 Correct 2 ms 5724 KB Output is correct
87 Correct 3 ms 5724 KB Output is correct
88 Correct 2 ms 5724 KB Output is correct
89 Correct 2 ms 5724 KB Output is correct
90 Correct 2 ms 5724 KB Output is correct
91 Correct 2 ms 5724 KB Output is correct
92 Correct 3 ms 5724 KB Output is correct
93 Correct 3 ms 5720 KB Output is correct
94 Correct 1 ms 5724 KB Output is correct
95 Correct 2 ms 5724 KB Output is correct
96 Correct 2 ms 5720 KB Output is correct
97 Correct 2 ms 5724 KB Output is correct
98 Correct 1 ms 5724 KB Output is correct
99 Correct 1 ms 5720 KB Output is correct
100 Correct 1 ms 5724 KB Output is correct
101 Correct 1 ms 5724 KB Output is correct
102 Correct 1 ms 5720 KB Output is correct
103 Correct 1 ms 5720 KB Output is correct
104 Correct 5 ms 6236 KB Output is correct
105 Correct 10 ms 7516 KB Output is correct
106 Correct 2 ms 5724 KB Output is correct
107 Correct 19 ms 8676 KB Output is correct
108 Correct 27 ms 10716 KB Output is correct
109 Correct 2 ms 5724 KB Output is correct
110 Correct 35 ms 11004 KB Output is correct
111 Correct 47 ms 11996 KB Output is correct
112 Correct 2 ms 5720 KB Output is correct
113 Correct 55 ms 17084 KB Output is correct
114 Correct 18 ms 8100 KB Output is correct
115 Correct 28 ms 8156 KB Output is correct
116 Correct 18 ms 8152 KB Output is correct
117 Correct 21 ms 8156 KB Output is correct
118 Correct 18 ms 8156 KB Output is correct
119 Correct 19 ms 8508 KB Output is correct
120 Correct 20 ms 8208 KB Output is correct
121 Correct 19 ms 8148 KB Output is correct
122 Correct 25 ms 8028 KB Output is correct
123 Correct 22 ms 8284 KB Output is correct
124 Correct 2 ms 5720 KB Output is correct
125 Correct 10 ms 6360 KB Output is correct
126 Correct 10 ms 6356 KB Output is correct
127 Correct 10 ms 6360 KB Output is correct
128 Correct 10 ms 6612 KB Output is correct
129 Correct 10 ms 6268 KB Output is correct
130 Correct 10 ms 6360 KB Output is correct
131 Correct 12 ms 6356 KB Output is correct
132 Correct 10 ms 6360 KB Output is correct
133 Incorrect 1 ms 5724 KB Output isn't correct
134 Halted 0 ms 0 KB -