Submission #1013739

# Submission time Handle Problem Language Result Execution time Memory
1013739 2024-07-04T05:18:08 Z huutuan Dreaming (IOI13_dreaming) C++14
65 / 100
42 ms 16128 KB
#include "dreaming.h"

#include <bits/stdc++.h>

using namespace std;

const int N=1e5+10;
vector<pair<int, int>> g[N];
int vis[N], n, m, l, dis[N], par[N];
int mx=-1;

void dfs(int u){
   vis[u]=1;
   if (mx==-1 || dis[mx]<dis[u]) mx=u;
   for (auto &e:g[u]){
      int v=e.first, w=e.second;
      if (v==par[u]) continue;
      par[v]=u; dis[v]=dis[u]+w;
      dfs(v);
   }
}

pair<int, int> find_diameter(int u){
   mx=-1; dis[u]=0; par[u]=-1; dfs(u);
   u=mx; mx=-1; dis[u]=0; par[u]=-1; dfs(u);
   int v=mx;
   pair<int, int> ans;
   ans.first=dis[v];
   ans.second=1e9;
   while (v!=-1){
      ans.second=min(ans.second, max(dis[v], dis[mx]-dis[v]));
      v=par[v];
   }
   return ans;
}

int travelTime(int _N, int M, int L, int A[], int B[], int T[]) {
   n=_N, m=M, l=L;
   for (int i=0; i<m; ++i) g[A[i]].emplace_back(B[i], T[i]), g[B[i]].emplace_back(A[i], T[i]);
   vector<pair<int, int>> v;
   for (int i=0; i<n; ++i) if (!vis[i]){
      v.push_back(find_diameter(i));
   }
   if ((int)v.size()==1) return v[0].first;
   if ((int)v.size()==2) return max({v[0].first, v[1].first, v[0].second+v[1].second+l});
   sort(v.begin(), v.end(), [&](pair<int, int> x, pair<int, int> y){ return x.second>y.second; });
   return max(v[0].second+v[1].second+l, v[1].second+v[2].second+l+l);
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13648 KB Output is correct
2 Correct 31 ms 14676 KB Output is correct
3 Correct 18 ms 11608 KB Output is correct
4 Correct 5 ms 6468 KB Output is correct
5 Correct 4 ms 5724 KB Output is correct
6 Correct 12 ms 7108 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 17 ms 8380 KB Output is correct
9 Correct 21 ms 9812 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 28 ms 11204 KB Output is correct
12 Correct 29 ms 12888 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13648 KB Output is correct
2 Correct 31 ms 14676 KB Output is correct
3 Correct 18 ms 11608 KB Output is correct
4 Correct 5 ms 6468 KB Output is correct
5 Correct 4 ms 5724 KB Output is correct
6 Correct 12 ms 7108 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 17 ms 8380 KB Output is correct
9 Correct 21 ms 9812 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 28 ms 11204 KB Output is correct
12 Correct 29 ms 12888 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4952 KB Output is correct
25 Correct 1 ms 4952 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 1 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 1 ms 4952 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 1 ms 4956 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 1 ms 4956 KB Output is correct
37 Correct 1 ms 4956 KB Output is correct
38 Correct 1 ms 4956 KB Output is correct
39 Correct 28 ms 14680 KB Output is correct
40 Correct 27 ms 14684 KB Output is correct
41 Correct 19 ms 11608 KB Output is correct
42 Correct 6 ms 6236 KB Output is correct
43 Correct 1 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 1 ms 4956 KB Output is correct
46 Correct 1 ms 4956 KB Output is correct
47 Correct 1 ms 4956 KB Output is correct
48 Correct 1 ms 4956 KB Output is correct
49 Correct 1 ms 4956 KB Output is correct
50 Correct 1 ms 4952 KB Output is correct
51 Correct 1 ms 4960 KB Output is correct
52 Correct 1 ms 4956 KB Output is correct
53 Correct 1 ms 4956 KB Output is correct
54 Correct 1 ms 4956 KB Output is correct
55 Correct 1 ms 4956 KB Output is correct
56 Correct 1 ms 4956 KB Output is correct
57 Correct 38 ms 10344 KB Output is correct
58 Correct 34 ms 10328 KB Output is correct
59 Correct 32 ms 10228 KB Output is correct
60 Correct 31 ms 10376 KB Output is correct
61 Correct 31 ms 10332 KB Output is correct
62 Correct 41 ms 10324 KB Output is correct
63 Correct 31 ms 10076 KB Output is correct
64 Correct 30 ms 10068 KB Output is correct
65 Correct 30 ms 10180 KB Output is correct
66 Correct 31 ms 10332 KB Output is correct
67 Correct 33 ms 10320 KB Output is correct
68 Correct 33 ms 10320 KB Output is correct
69 Correct 35 ms 10632 KB Output is correct
70 Correct 33 ms 10588 KB Output is correct
71 Correct 1 ms 4956 KB Output is correct
72 Correct 2 ms 4956 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 2 ms 4956 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 5212 KB Output is correct
77 Correct 2 ms 4956 KB Output is correct
78 Correct 2 ms 4952 KB Output is correct
79 Correct 2 ms 4956 KB Output is correct
80 Correct 33 ms 10332 KB Output is correct
81 Correct 34 ms 10320 KB Output is correct
82 Correct 35 ms 10348 KB Output is correct
83 Correct 30 ms 10428 KB Output is correct
84 Correct 2 ms 4968 KB Output is correct
85 Correct 1 ms 4956 KB Output is correct
86 Correct 2 ms 4952 KB Output is correct
87 Correct 2 ms 4956 KB Output is correct
88 Correct 2 ms 4952 KB Output is correct
89 Correct 2 ms 5032 KB Output is correct
90 Correct 1 ms 4956 KB Output is correct
91 Correct 2 ms 4956 KB Output is correct
92 Correct 1 ms 4956 KB Output is correct
93 Correct 1 ms 4964 KB Output is correct
94 Correct 1 ms 4956 KB Output is correct
95 Correct 1 ms 4956 KB Output is correct
96 Correct 1 ms 4956 KB Output is correct
97 Correct 1 ms 4956 KB Output is correct
98 Correct 1 ms 4956 KB Output is correct
99 Correct 1 ms 4956 KB Output is correct
100 Correct 1 ms 4956 KB Output is correct
101 Correct 1 ms 4956 KB Output is correct
102 Correct 1 ms 4952 KB Output is correct
103 Correct 1 ms 4956 KB Output is correct
104 Correct 4 ms 5724 KB Output is correct
105 Correct 8 ms 7052 KB Output is correct
106 Correct 1 ms 4956 KB Output is correct
107 Correct 15 ms 8324 KB Output is correct
108 Correct 19 ms 9772 KB Output is correct
109 Correct 1 ms 4952 KB Output is correct
110 Correct 26 ms 11356 KB Output is correct
111 Correct 29 ms 12844 KB Output is correct
112 Correct 1 ms 4952 KB Output is correct
113 Correct 42 ms 16128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 7648 KB Output is correct
2 Correct 13 ms 7644 KB Output is correct
3 Correct 19 ms 7648 KB Output is correct
4 Correct 13 ms 7584 KB Output is correct
5 Correct 14 ms 7588 KB Output is correct
6 Correct 14 ms 8220 KB Output is correct
7 Correct 13 ms 7728 KB Output is correct
8 Correct 12 ms 7648 KB Output is correct
9 Correct 13 ms 7636 KB Output is correct
10 Correct 14 ms 7640 KB Output is correct
11 Correct 1 ms 4956 KB Output is correct
12 Correct 5 ms 6100 KB Output is correct
13 Correct 4 ms 6100 KB Output is correct
14 Correct 3 ms 6100 KB Output is correct
15 Correct 4 ms 6100 KB Output is correct
16 Correct 4 ms 6068 KB Output is correct
17 Correct 4 ms 6100 KB Output is correct
18 Correct 4 ms 6100 KB Output is correct
19 Correct 4 ms 6100 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 4 ms 6100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 1 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 1 ms 4956 KB Output is correct
9 Correct 1 ms 4956 KB Output is correct
10 Correct 1 ms 4956 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4952 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4952 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4956 KB Output is correct
25 Correct 1 ms 4956 KB Output is correct
26 Incorrect 2 ms 4956 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 26 ms 13648 KB Output is correct
2 Correct 31 ms 14676 KB Output is correct
3 Correct 18 ms 11608 KB Output is correct
4 Correct 5 ms 6468 KB Output is correct
5 Correct 4 ms 5724 KB Output is correct
6 Correct 12 ms 7108 KB Output is correct
7 Correct 1 ms 4956 KB Output is correct
8 Correct 17 ms 8380 KB Output is correct
9 Correct 21 ms 9812 KB Output is correct
10 Correct 1 ms 4952 KB Output is correct
11 Correct 28 ms 11204 KB Output is correct
12 Correct 29 ms 12888 KB Output is correct
13 Correct 1 ms 4956 KB Output is correct
14 Correct 1 ms 4952 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 4956 KB Output is correct
17 Correct 1 ms 4956 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
21 Correct 1 ms 4956 KB Output is correct
22 Correct 1 ms 4956 KB Output is correct
23 Correct 1 ms 4956 KB Output is correct
24 Correct 1 ms 4952 KB Output is correct
25 Correct 1 ms 4952 KB Output is correct
26 Correct 1 ms 4956 KB Output is correct
27 Correct 1 ms 4956 KB Output is correct
28 Correct 1 ms 4956 KB Output is correct
29 Correct 1 ms 4952 KB Output is correct
30 Correct 1 ms 4956 KB Output is correct
31 Correct 1 ms 4956 KB Output is correct
32 Correct 1 ms 4956 KB Output is correct
33 Correct 1 ms 4956 KB Output is correct
34 Correct 1 ms 4956 KB Output is correct
35 Correct 1 ms 4956 KB Output is correct
36 Correct 1 ms 4956 KB Output is correct
37 Correct 1 ms 4956 KB Output is correct
38 Correct 1 ms 4956 KB Output is correct
39 Correct 28 ms 14680 KB Output is correct
40 Correct 27 ms 14684 KB Output is correct
41 Correct 19 ms 11608 KB Output is correct
42 Correct 6 ms 6236 KB Output is correct
43 Correct 1 ms 4956 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 1 ms 4956 KB Output is correct
46 Correct 1 ms 4956 KB Output is correct
47 Correct 1 ms 4956 KB Output is correct
48 Correct 1 ms 4956 KB Output is correct
49 Correct 1 ms 4956 KB Output is correct
50 Correct 1 ms 4952 KB Output is correct
51 Correct 1 ms 4960 KB Output is correct
52 Correct 1 ms 4956 KB Output is correct
53 Correct 1 ms 4956 KB Output is correct
54 Correct 1 ms 4956 KB Output is correct
55 Correct 1 ms 4956 KB Output is correct
56 Correct 1 ms 4956 KB Output is correct
57 Correct 38 ms 10344 KB Output is correct
58 Correct 34 ms 10328 KB Output is correct
59 Correct 32 ms 10228 KB Output is correct
60 Correct 31 ms 10376 KB Output is correct
61 Correct 31 ms 10332 KB Output is correct
62 Correct 41 ms 10324 KB Output is correct
63 Correct 31 ms 10076 KB Output is correct
64 Correct 30 ms 10068 KB Output is correct
65 Correct 30 ms 10180 KB Output is correct
66 Correct 31 ms 10332 KB Output is correct
67 Correct 33 ms 10320 KB Output is correct
68 Correct 33 ms 10320 KB Output is correct
69 Correct 35 ms 10632 KB Output is correct
70 Correct 33 ms 10588 KB Output is correct
71 Correct 1 ms 4956 KB Output is correct
72 Correct 2 ms 4956 KB Output is correct
73 Correct 2 ms 4956 KB Output is correct
74 Correct 2 ms 4956 KB Output is correct
75 Correct 2 ms 4956 KB Output is correct
76 Correct 2 ms 5212 KB Output is correct
77 Correct 2 ms 4956 KB Output is correct
78 Correct 2 ms 4952 KB Output is correct
79 Correct 2 ms 4956 KB Output is correct
80 Correct 33 ms 10332 KB Output is correct
81 Correct 34 ms 10320 KB Output is correct
82 Correct 35 ms 10348 KB Output is correct
83 Correct 30 ms 10428 KB Output is correct
84 Correct 2 ms 4968 KB Output is correct
85 Correct 1 ms 4956 KB Output is correct
86 Correct 2 ms 4952 KB Output is correct
87 Correct 2 ms 4956 KB Output is correct
88 Correct 2 ms 4952 KB Output is correct
89 Correct 2 ms 5032 KB Output is correct
90 Correct 1 ms 4956 KB Output is correct
91 Correct 2 ms 4956 KB Output is correct
92 Correct 1 ms 4956 KB Output is correct
93 Correct 1 ms 4964 KB Output is correct
94 Correct 1 ms 4956 KB Output is correct
95 Correct 1 ms 4956 KB Output is correct
96 Correct 1 ms 4956 KB Output is correct
97 Correct 1 ms 4956 KB Output is correct
98 Correct 1 ms 4956 KB Output is correct
99 Correct 1 ms 4956 KB Output is correct
100 Correct 1 ms 4956 KB Output is correct
101 Correct 1 ms 4956 KB Output is correct
102 Correct 1 ms 4952 KB Output is correct
103 Correct 1 ms 4956 KB Output is correct
104 Correct 4 ms 5724 KB Output is correct
105 Correct 8 ms 7052 KB Output is correct
106 Correct 1 ms 4956 KB Output is correct
107 Correct 15 ms 8324 KB Output is correct
108 Correct 19 ms 9772 KB Output is correct
109 Correct 1 ms 4952 KB Output is correct
110 Correct 26 ms 11356 KB Output is correct
111 Correct 29 ms 12844 KB Output is correct
112 Correct 1 ms 4952 KB Output is correct
113 Correct 42 ms 16128 KB Output is correct
114 Correct 13 ms 7648 KB Output is correct
115 Correct 13 ms 7644 KB Output is correct
116 Correct 19 ms 7648 KB Output is correct
117 Correct 13 ms 7584 KB Output is correct
118 Correct 14 ms 7588 KB Output is correct
119 Correct 14 ms 8220 KB Output is correct
120 Correct 13 ms 7728 KB Output is correct
121 Correct 12 ms 7648 KB Output is correct
122 Correct 13 ms 7636 KB Output is correct
123 Correct 14 ms 7640 KB Output is correct
124 Correct 1 ms 4956 KB Output is correct
125 Correct 5 ms 6100 KB Output is correct
126 Correct 4 ms 6100 KB Output is correct
127 Correct 3 ms 6100 KB Output is correct
128 Correct 4 ms 6100 KB Output is correct
129 Correct 4 ms 6068 KB Output is correct
130 Correct 4 ms 6100 KB Output is correct
131 Correct 4 ms 6100 KB Output is correct
132 Correct 4 ms 6100 KB Output is correct
133 Correct 1 ms 4956 KB Output is correct
134 Correct 1 ms 4956 KB Output is correct
135 Correct 1 ms 4956 KB Output is correct
136 Correct 4 ms 6100 KB Output is correct
137 Incorrect 2 ms 4956 KB Output isn't correct
138 Halted 0 ms 0 KB -