Submission #842911

# Submission time Handle Problem Language Result Execution time Memory
842911 2023-09-03T13:16:10 Z 12345678 Dreaming (IOI13_dreaming) C++17
47 / 100
66 ms 30968 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;
int mx[nx], mxr[nx], nxt, mx1=INT_MAX, mx2=INT_MAX, ans;
bool vs[nx];
vector<vector<pair<int, int>>> d(nx);

void dfs(int u, int p)
{
    vs[u]=1;
    for (auto [v, w]:d[u])
    {
        if (v==p) continue;
        dfs(v, u);
        mx[u]=max(mx[u], mx[v]+w);
    }
}

void dfs2(int u, int p)
{
    vector<int> pf(d[u].size()+2), sf(d[u].size()+2);
    pf[0]=mxr[u];
    for (int i=d[u].size()-1; i>=0; i--)
    {
        sf[i+1]=sf[i+2];
        if (d[u][i].first==p) continue;
        sf[i+1]=max(sf[i+1], d[u][i].second+mx[d[u][i].first]);
    }
    for (int i=0; i<d[u].size(); i++)
    {
        pf[i+1]=pf[i];
        if (d[u][i].first==p) continue;
        pf[i+1]=max(pf[i+1], d[u][i].second+mx[d[u][i].first]);
        mxr[d[u][i].first]=max(pf[i], sf[i+2])+d[u][i].second;
    }
    for (auto [v, w]:d[u]) if (v!=p) dfs2(v, u);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i=0; i<M; i++) d[A[i]].push_back({B[i], T[i]}), d[B[i]].push_back({A[i], T[i]});
    dfs(0, 0); dfs2(0, 0);
    for (int i=0; i<N; i++)
    {
        if (!vs[i]) nxt=i;
        else vs[i]=0, mx1=min(mx1, max(mx[i], mxr[i]));
    }
    dfs(nxt, nxt); dfs2(nxt, nxt);
    for (int i=0; i<N; i++) if (vs[i]) mx2=min(mx2, max(mx[i], mxr[i]));
    for (int i=0; i<N; i++) ans=max(ans, mx[i]+mxr[i]);
    return max(ans, mx1+mx2+L);
}

Compilation message

dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i=0; i<d[u].size(); i++)
      |                   ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 38 ms 18516 KB Output is correct
2 Correct 40 ms 18768 KB Output is correct
3 Correct 29 ms 18004 KB Output is correct
4 Correct 10 ms 5212 KB Output is correct
5 Correct 5 ms 4184 KB Output is correct
6 Correct 10 ms 6488 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 23 ms 10472 KB Output is correct
9 Correct 25 ms 14416 KB Output is correct
10 Correct 2 ms 2904 KB Output is correct
11 Correct 40 ms 14592 KB Output is correct
12 Correct 41 ms 17100 KB Output is correct
13 Correct 2 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 1 ms 2812 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2648 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 2 ms 2816 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 2 ms 2648 KB Output is correct
22 Correct 2 ms 2808 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 1 ms 2648 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 18516 KB Output is correct
2 Correct 40 ms 18768 KB Output is correct
3 Correct 29 ms 18004 KB Output is correct
4 Correct 10 ms 5212 KB Output is correct
5 Correct 5 ms 4184 KB Output is correct
6 Correct 10 ms 6488 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 23 ms 10472 KB Output is correct
9 Correct 25 ms 14416 KB Output is correct
10 Correct 2 ms 2904 KB Output is correct
11 Correct 40 ms 14592 KB Output is correct
12 Correct 41 ms 17100 KB Output is correct
13 Correct 2 ms 2904 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2812 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2648 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
24 Correct 2 ms 2816 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2648 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 2 ms 2648 KB Output is correct
35 Correct 2 ms 2808 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 49 ms 19660 KB Output is correct
40 Correct 40 ms 18768 KB Output is correct
41 Correct 30 ms 18004 KB Output is correct
42 Correct 7 ms 5160 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 1 ms 2648 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2648 KB Output is correct
47 Correct 1 ms 2648 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 1 ms 2648 KB Output is correct
50 Correct 1 ms 2648 KB Output is correct
51 Correct 2 ms 2648 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 1 ms 2648 KB Output is correct
56 Correct 2 ms 2648 KB Output is correct
57 Correct 40 ms 10064 KB Output is correct
58 Correct 38 ms 10064 KB Output is correct
59 Correct 44 ms 10076 KB Output is correct
60 Correct 48 ms 10172 KB Output is correct
61 Correct 41 ms 10088 KB Output is correct
62 Correct 40 ms 10080 KB Output is correct
63 Correct 38 ms 10064 KB Output is correct
64 Correct 39 ms 9808 KB Output is correct
65 Correct 40 ms 10140 KB Output is correct
66 Correct 40 ms 10064 KB Output is correct
67 Correct 39 ms 10064 KB Output is correct
68 Correct 41 ms 10192 KB Output is correct
69 Correct 44 ms 10324 KB Output is correct
70 Correct 41 ms 10320 KB Output is correct
71 Correct 1 ms 2648 KB Output is correct
72 Correct 3 ms 2904 KB Output is correct
73 Correct 2 ms 2904 KB Output is correct
74 Correct 2 ms 2904 KB Output is correct
75 Correct 3 ms 2904 KB Output is correct
76 Correct 2 ms 3104 KB Output is correct
77 Correct 2 ms 2904 KB Output is correct
78 Correct 3 ms 2904 KB Output is correct
79 Correct 2 ms 2908 KB Output is correct
80 Correct 42 ms 10064 KB Output is correct
81 Correct 41 ms 10188 KB Output is correct
82 Correct 40 ms 10064 KB Output is correct
83 Correct 41 ms 10064 KB Output is correct
84 Correct 2 ms 2904 KB Output is correct
85 Correct 2 ms 2904 KB Output is correct
86 Correct 2 ms 2904 KB Output is correct
87 Correct 2 ms 2904 KB Output is correct
88 Correct 2 ms 2904 KB Output is correct
89 Correct 2 ms 2908 KB Output is correct
90 Correct 2 ms 2904 KB Output is correct
91 Correct 3 ms 2904 KB Output is correct
92 Correct 2 ms 2904 KB Output is correct
93 Correct 3 ms 2904 KB Output is correct
94 Correct 1 ms 2648 KB Output is correct
95 Correct 1 ms 2648 KB Output is correct
96 Correct 1 ms 2648 KB Output is correct
97 Correct 1 ms 2648 KB Output is correct
98 Correct 1 ms 2648 KB Output is correct
99 Correct 2 ms 2648 KB Output is correct
100 Correct 1 ms 2652 KB Output is correct
101 Correct 1 ms 2648 KB Output is correct
102 Correct 1 ms 2648 KB Output is correct
103 Correct 1 ms 2652 KB Output is correct
104 Correct 5 ms 4184 KB Output is correct
105 Correct 10 ms 6488 KB Output is correct
106 Correct 2 ms 2648 KB Output is correct
107 Correct 20 ms 10584 KB Output is correct
108 Correct 26 ms 14416 KB Output is correct
109 Correct 2 ms 2904 KB Output is correct
110 Correct 37 ms 14672 KB Output is correct
111 Correct 38 ms 16980 KB Output is correct
112 Correct 1 ms 2904 KB Output is correct
113 Correct 66 ms 30968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 12 ms 5208 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2648 KB Output is correct
2 Correct 2 ms 2648 KB Output is correct
3 Correct 1 ms 2648 KB Output is correct
4 Correct 1 ms 2648 KB Output is correct
5 Correct 2 ms 2648 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 1 ms 2812 KB Output is correct
8 Correct 1 ms 2652 KB Output is correct
9 Correct 2 ms 2648 KB Output is correct
10 Correct 2 ms 2648 KB Output is correct
11 Correct 2 ms 2816 KB Output is correct
12 Correct 1 ms 2648 KB Output is correct
13 Correct 1 ms 2648 KB Output is correct
14 Correct 1 ms 2652 KB Output is correct
15 Correct 2 ms 2652 KB Output is correct
16 Correct 2 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 1 ms 2648 KB Output is correct
19 Correct 1 ms 2648 KB Output is correct
20 Correct 1 ms 2648 KB Output is correct
21 Correct 2 ms 2648 KB Output is correct
22 Correct 2 ms 2808 KB Output is correct
23 Correct 1 ms 2648 KB Output is correct
24 Correct 1 ms 2648 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Incorrect 1 ms 2648 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 38 ms 18516 KB Output is correct
2 Correct 40 ms 18768 KB Output is correct
3 Correct 29 ms 18004 KB Output is correct
4 Correct 10 ms 5212 KB Output is correct
5 Correct 5 ms 4184 KB Output is correct
6 Correct 10 ms 6488 KB Output is correct
7 Correct 1 ms 2648 KB Output is correct
8 Correct 23 ms 10472 KB Output is correct
9 Correct 25 ms 14416 KB Output is correct
10 Correct 2 ms 2904 KB Output is correct
11 Correct 40 ms 14592 KB Output is correct
12 Correct 41 ms 17100 KB Output is correct
13 Correct 2 ms 2904 KB Output is correct
14 Correct 1 ms 2648 KB Output is correct
15 Correct 2 ms 2648 KB Output is correct
16 Correct 1 ms 2648 KB Output is correct
17 Correct 1 ms 2648 KB Output is correct
18 Correct 2 ms 2648 KB Output is correct
19 Correct 2 ms 2652 KB Output is correct
20 Correct 1 ms 2812 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2648 KB Output is correct
23 Correct 2 ms 2648 KB Output is correct
24 Correct 2 ms 2816 KB Output is correct
25 Correct 1 ms 2648 KB Output is correct
26 Correct 1 ms 2648 KB Output is correct
27 Correct 1 ms 2652 KB Output is correct
28 Correct 2 ms 2652 KB Output is correct
29 Correct 2 ms 2648 KB Output is correct
30 Correct 1 ms 2648 KB Output is correct
31 Correct 1 ms 2648 KB Output is correct
32 Correct 1 ms 2648 KB Output is correct
33 Correct 1 ms 2648 KB Output is correct
34 Correct 2 ms 2648 KB Output is correct
35 Correct 2 ms 2808 KB Output is correct
36 Correct 1 ms 2648 KB Output is correct
37 Correct 1 ms 2648 KB Output is correct
38 Correct 1 ms 2648 KB Output is correct
39 Correct 49 ms 19660 KB Output is correct
40 Correct 40 ms 18768 KB Output is correct
41 Correct 30 ms 18004 KB Output is correct
42 Correct 7 ms 5160 KB Output is correct
43 Correct 1 ms 2648 KB Output is correct
44 Correct 1 ms 2648 KB Output is correct
45 Correct 2 ms 2652 KB Output is correct
46 Correct 2 ms 2648 KB Output is correct
47 Correct 1 ms 2648 KB Output is correct
48 Correct 2 ms 2652 KB Output is correct
49 Correct 1 ms 2648 KB Output is correct
50 Correct 1 ms 2648 KB Output is correct
51 Correct 2 ms 2648 KB Output is correct
52 Correct 1 ms 2652 KB Output is correct
53 Correct 1 ms 2652 KB Output is correct
54 Correct 1 ms 2652 KB Output is correct
55 Correct 1 ms 2648 KB Output is correct
56 Correct 2 ms 2648 KB Output is correct
57 Correct 40 ms 10064 KB Output is correct
58 Correct 38 ms 10064 KB Output is correct
59 Correct 44 ms 10076 KB Output is correct
60 Correct 48 ms 10172 KB Output is correct
61 Correct 41 ms 10088 KB Output is correct
62 Correct 40 ms 10080 KB Output is correct
63 Correct 38 ms 10064 KB Output is correct
64 Correct 39 ms 9808 KB Output is correct
65 Correct 40 ms 10140 KB Output is correct
66 Correct 40 ms 10064 KB Output is correct
67 Correct 39 ms 10064 KB Output is correct
68 Correct 41 ms 10192 KB Output is correct
69 Correct 44 ms 10324 KB Output is correct
70 Correct 41 ms 10320 KB Output is correct
71 Correct 1 ms 2648 KB Output is correct
72 Correct 3 ms 2904 KB Output is correct
73 Correct 2 ms 2904 KB Output is correct
74 Correct 2 ms 2904 KB Output is correct
75 Correct 3 ms 2904 KB Output is correct
76 Correct 2 ms 3104 KB Output is correct
77 Correct 2 ms 2904 KB Output is correct
78 Correct 3 ms 2904 KB Output is correct
79 Correct 2 ms 2908 KB Output is correct
80 Correct 42 ms 10064 KB Output is correct
81 Correct 41 ms 10188 KB Output is correct
82 Correct 40 ms 10064 KB Output is correct
83 Correct 41 ms 10064 KB Output is correct
84 Correct 2 ms 2904 KB Output is correct
85 Correct 2 ms 2904 KB Output is correct
86 Correct 2 ms 2904 KB Output is correct
87 Correct 2 ms 2904 KB Output is correct
88 Correct 2 ms 2904 KB Output is correct
89 Correct 2 ms 2908 KB Output is correct
90 Correct 2 ms 2904 KB Output is correct
91 Correct 3 ms 2904 KB Output is correct
92 Correct 2 ms 2904 KB Output is correct
93 Correct 3 ms 2904 KB Output is correct
94 Correct 1 ms 2648 KB Output is correct
95 Correct 1 ms 2648 KB Output is correct
96 Correct 1 ms 2648 KB Output is correct
97 Correct 1 ms 2648 KB Output is correct
98 Correct 1 ms 2648 KB Output is correct
99 Correct 2 ms 2648 KB Output is correct
100 Correct 1 ms 2652 KB Output is correct
101 Correct 1 ms 2648 KB Output is correct
102 Correct 1 ms 2648 KB Output is correct
103 Correct 1 ms 2652 KB Output is correct
104 Correct 5 ms 4184 KB Output is correct
105 Correct 10 ms 6488 KB Output is correct
106 Correct 2 ms 2648 KB Output is correct
107 Correct 20 ms 10584 KB Output is correct
108 Correct 26 ms 14416 KB Output is correct
109 Correct 2 ms 2904 KB Output is correct
110 Correct 37 ms 14672 KB Output is correct
111 Correct 38 ms 16980 KB Output is correct
112 Correct 1 ms 2904 KB Output is correct
113 Correct 66 ms 30968 KB Output is correct
114 Incorrect 12 ms 5208 KB Output isn't correct
115 Halted 0 ms 0 KB -