Submission #240673

# Submission time Handle Problem Language Result Execution time Memory
240673 2020-06-20T15:06:52 Z s_avila_g Dreaming (IOI13_dreaming) C++14
47 / 100
133 ms 13304 KB
#include <bits/stdc++.h>
#include "dreaming.h"
#define ff first
#define ss second
using namespace std;
int inf = INT_MAX;
vector<vector<pair<int,int> > > gp;
vector<int> vis, dis,parents;

void dfs(int u, int pes){
    vis[u] = 1;
    dis[u] += pes;
    for(auto it: gp[u]){
        if(vis[it.ff] == 0){
            vis[it.ff] = 1;
            parents[it.ff] = u;
            dfs(it.ff, it.ss + dis[u]);
        }
    }
}

int radius(int u){
    int distan1 = dis[u], distan2 = 0, ans = dis[u];
    while(parents[u] != -1){
        ans = min(ans,max(distan1,distan2));
        int pospar = -1;
        for(int i = 0; i < (int)gp[u].size(); i++){
            if(gp[u][i].ff == parents[u]) pospar = gp[u][i].ss;
        }
        u = parents[u];
        distan1 -= pospar; distan2 += pospar;
    }
    return ans;
}

int fndext(int n){
    int ans = 0, maypes = 0;
    for(int i = 0; i < n; i++){
        if(dis[i] > maypes){
            maypes = dis[i];
            ans = i;
        }
    }
    return ans;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    gp.resize(N); vis.resize(N); dis.resize(N); parents.resize(N);
    for(int i = 0; i < N; i++) vis[i] = 0, dis[i] = 0;
    for(int i = 0; i < M; i++){
        gp[A[i]].push_back(make_pair(B[i],T[i]));
        gp[B[i]].push_back(make_pair(A[i],T[i]));
    }
    dfs(0,0);
    int nodext1, nodext2, nodext11, nodext22;
    nodext1 = fndext(N);
    dis.clear();
    for(int i = 0; i < N; i++) vis[i] = 0, dis[i] = 0;
    parents[nodext1] = -1;
    dfs(nodext1,0);
    nodext2 = fndext(N);
    int diam1 = dis[nodext2], diam2 = 0, radi1 = radius(nodext2), radi2 = 0;
    for(int i = 0; i < N; i++) dis[i] = 0;
    int posext;
    for(int i = 0; i < N; i++){
        if(vis[i] == 0){
            dfs(i,0);
            posext = i;
        }
    }
    bool calc = false;
    for(int i = 0; i < N; i++){
        if(dis[i] != 0) calc = true;
    }
    if(calc) nodext11 = fndext(N);
    else nodext11 = posext;
    dis.clear();
    for(int i = 0; i < N; i++) vis[i] = 0, dis[i] = 0;
    parents[nodext11] = -1;
    dfs(nodext11,0);
    nodext22 = fndext(N);
    diam2 = dis[nodext22];
    radi2 = radius(nodext22);
    return max(diam1,max(diam2,radi1 + radi2 + L));
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:79:21: warning: 'posext' may be used uninitialized in this function [-Wmaybe-uninitialized]
     parents[nodext11] = -1;
                     ^
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11768 KB Output is correct
2 Correct 58 ms 11792 KB Output is correct
3 Correct 40 ms 7808 KB Output is correct
4 Correct 12 ms 2048 KB Output is correct
5 Correct 10 ms 1408 KB Output is correct
6 Correct 17 ms 2816 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 32 ms 4600 KB Output is correct
9 Correct 37 ms 6144 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 74 ms 8056 KB Output is correct
12 Correct 69 ms 9848 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11768 KB Output is correct
2 Correct 58 ms 11792 KB Output is correct
3 Correct 40 ms 7808 KB Output is correct
4 Correct 12 ms 2048 KB Output is correct
5 Correct 10 ms 1408 KB Output is correct
6 Correct 17 ms 2816 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 32 ms 4600 KB Output is correct
9 Correct 37 ms 6144 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 74 ms 8056 KB Output is correct
12 Correct 69 ms 9848 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 256 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11768 KB Output is correct
2 Correct 58 ms 11792 KB Output is correct
3 Correct 40 ms 7808 KB Output is correct
4 Correct 12 ms 2048 KB Output is correct
5 Correct 10 ms 1408 KB Output is correct
6 Correct 17 ms 2816 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 32 ms 4600 KB Output is correct
9 Correct 37 ms 6144 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 74 ms 8056 KB Output is correct
12 Correct 69 ms 9848 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 256 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 65 ms 12280 KB Output is correct
40 Correct 59 ms 12280 KB Output is correct
41 Correct 43 ms 8320 KB Output is correct
42 Correct 12 ms 2176 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 80 ms 9464 KB Output is correct
58 Correct 117 ms 9464 KB Output is correct
59 Correct 83 ms 9440 KB Output is correct
60 Correct 111 ms 9464 KB Output is correct
61 Correct 86 ms 9336 KB Output is correct
62 Correct 108 ms 9592 KB Output is correct
63 Correct 75 ms 9208 KB Output is correct
64 Correct 75 ms 9208 KB Output is correct
65 Correct 79 ms 9208 KB Output is correct
66 Correct 120 ms 9208 KB Output is correct
67 Correct 91 ms 9464 KB Output is correct
68 Correct 115 ms 9452 KB Output is correct
69 Correct 111 ms 9464 KB Output is correct
70 Correct 116 ms 9464 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 6 ms 640 KB Output is correct
73 Correct 7 ms 640 KB Output is correct
74 Correct 6 ms 640 KB Output is correct
75 Correct 6 ms 640 KB Output is correct
76 Correct 6 ms 640 KB Output is correct
77 Correct 7 ms 640 KB Output is correct
78 Correct 6 ms 640 KB Output is correct
79 Correct 7 ms 640 KB Output is correct
80 Correct 86 ms 9476 KB Output is correct
81 Correct 84 ms 9464 KB Output is correct
82 Correct 87 ms 9336 KB Output is correct
83 Correct 133 ms 9336 KB Output is correct
84 Correct 6 ms 512 KB Output is correct
85 Correct 6 ms 512 KB Output is correct
86 Correct 6 ms 512 KB Output is correct
87 Correct 6 ms 512 KB Output is correct
88 Correct 6 ms 640 KB Output is correct
89 Correct 6 ms 512 KB Output is correct
90 Correct 6 ms 640 KB Output is correct
91 Correct 6 ms 640 KB Output is correct
92 Correct 6 ms 596 KB Output is correct
93 Correct 6 ms 640 KB Output is correct
94 Correct 5 ms 384 KB Output is correct
95 Correct 5 ms 384 KB Output is correct
96 Correct 5 ms 384 KB Output is correct
97 Correct 6 ms 384 KB Output is correct
98 Correct 5 ms 384 KB Output is correct
99 Correct 5 ms 384 KB Output is correct
100 Correct 5 ms 384 KB Output is correct
101 Correct 5 ms 384 KB Output is correct
102 Correct 5 ms 384 KB Output is correct
103 Correct 5 ms 384 KB Output is correct
104 Correct 11 ms 1536 KB Output is correct
105 Correct 18 ms 3200 KB Output is correct
106 Correct 5 ms 384 KB Output is correct
107 Correct 32 ms 5112 KB Output is correct
108 Correct 38 ms 6648 KB Output is correct
109 Correct 5 ms 384 KB Output is correct
110 Correct 58 ms 8568 KB Output is correct
111 Correct 96 ms 10360 KB Output is correct
112 Correct 6 ms 384 KB Output is correct
113 Correct 111 ms 13304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 6016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11768 KB Output is correct
2 Correct 58 ms 11792 KB Output is correct
3 Correct 40 ms 7808 KB Output is correct
4 Correct 12 ms 2048 KB Output is correct
5 Correct 10 ms 1408 KB Output is correct
6 Correct 17 ms 2816 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 32 ms 4600 KB Output is correct
9 Correct 37 ms 6144 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 74 ms 8056 KB Output is correct
12 Correct 69 ms 9848 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 6 ms 512 KB Output is correct
16 Correct 6 ms 640 KB Output is correct
17 Incorrect 5 ms 384 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 59 ms 11768 KB Output is correct
2 Correct 58 ms 11792 KB Output is correct
3 Correct 40 ms 7808 KB Output is correct
4 Correct 12 ms 2048 KB Output is correct
5 Correct 10 ms 1408 KB Output is correct
6 Correct 17 ms 2816 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 32 ms 4600 KB Output is correct
9 Correct 37 ms 6144 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 74 ms 8056 KB Output is correct
12 Correct 69 ms 9848 KB Output is correct
13 Correct 6 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 5 ms 384 KB Output is correct
17 Correct 5 ms 384 KB Output is correct
18 Correct 5 ms 384 KB Output is correct
19 Correct 4 ms 384 KB Output is correct
20 Correct 5 ms 384 KB Output is correct
21 Correct 5 ms 384 KB Output is correct
22 Correct 5 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 5 ms 384 KB Output is correct
25 Correct 5 ms 384 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 4 ms 384 KB Output is correct
28 Correct 5 ms 256 KB Output is correct
29 Correct 5 ms 384 KB Output is correct
30 Correct 5 ms 384 KB Output is correct
31 Correct 5 ms 384 KB Output is correct
32 Correct 5 ms 384 KB Output is correct
33 Correct 5 ms 384 KB Output is correct
34 Correct 5 ms 384 KB Output is correct
35 Correct 5 ms 512 KB Output is correct
36 Correct 4 ms 384 KB Output is correct
37 Correct 5 ms 384 KB Output is correct
38 Correct 4 ms 384 KB Output is correct
39 Correct 65 ms 12280 KB Output is correct
40 Correct 59 ms 12280 KB Output is correct
41 Correct 43 ms 8320 KB Output is correct
42 Correct 12 ms 2176 KB Output is correct
43 Correct 5 ms 384 KB Output is correct
44 Correct 5 ms 384 KB Output is correct
45 Correct 5 ms 384 KB Output is correct
46 Correct 5 ms 384 KB Output is correct
47 Correct 5 ms 384 KB Output is correct
48 Correct 5 ms 384 KB Output is correct
49 Correct 5 ms 384 KB Output is correct
50 Correct 5 ms 384 KB Output is correct
51 Correct 5 ms 384 KB Output is correct
52 Correct 5 ms 384 KB Output is correct
53 Correct 5 ms 384 KB Output is correct
54 Correct 5 ms 384 KB Output is correct
55 Correct 5 ms 384 KB Output is correct
56 Correct 5 ms 384 KB Output is correct
57 Correct 80 ms 9464 KB Output is correct
58 Correct 117 ms 9464 KB Output is correct
59 Correct 83 ms 9440 KB Output is correct
60 Correct 111 ms 9464 KB Output is correct
61 Correct 86 ms 9336 KB Output is correct
62 Correct 108 ms 9592 KB Output is correct
63 Correct 75 ms 9208 KB Output is correct
64 Correct 75 ms 9208 KB Output is correct
65 Correct 79 ms 9208 KB Output is correct
66 Correct 120 ms 9208 KB Output is correct
67 Correct 91 ms 9464 KB Output is correct
68 Correct 115 ms 9452 KB Output is correct
69 Correct 111 ms 9464 KB Output is correct
70 Correct 116 ms 9464 KB Output is correct
71 Correct 5 ms 384 KB Output is correct
72 Correct 6 ms 640 KB Output is correct
73 Correct 7 ms 640 KB Output is correct
74 Correct 6 ms 640 KB Output is correct
75 Correct 6 ms 640 KB Output is correct
76 Correct 6 ms 640 KB Output is correct
77 Correct 7 ms 640 KB Output is correct
78 Correct 6 ms 640 KB Output is correct
79 Correct 7 ms 640 KB Output is correct
80 Correct 86 ms 9476 KB Output is correct
81 Correct 84 ms 9464 KB Output is correct
82 Correct 87 ms 9336 KB Output is correct
83 Correct 133 ms 9336 KB Output is correct
84 Correct 6 ms 512 KB Output is correct
85 Correct 6 ms 512 KB Output is correct
86 Correct 6 ms 512 KB Output is correct
87 Correct 6 ms 512 KB Output is correct
88 Correct 6 ms 640 KB Output is correct
89 Correct 6 ms 512 KB Output is correct
90 Correct 6 ms 640 KB Output is correct
91 Correct 6 ms 640 KB Output is correct
92 Correct 6 ms 596 KB Output is correct
93 Correct 6 ms 640 KB Output is correct
94 Correct 5 ms 384 KB Output is correct
95 Correct 5 ms 384 KB Output is correct
96 Correct 5 ms 384 KB Output is correct
97 Correct 6 ms 384 KB Output is correct
98 Correct 5 ms 384 KB Output is correct
99 Correct 5 ms 384 KB Output is correct
100 Correct 5 ms 384 KB Output is correct
101 Correct 5 ms 384 KB Output is correct
102 Correct 5 ms 384 KB Output is correct
103 Correct 5 ms 384 KB Output is correct
104 Correct 11 ms 1536 KB Output is correct
105 Correct 18 ms 3200 KB Output is correct
106 Correct 5 ms 384 KB Output is correct
107 Correct 32 ms 5112 KB Output is correct
108 Correct 38 ms 6648 KB Output is correct
109 Correct 5 ms 384 KB Output is correct
110 Correct 58 ms 8568 KB Output is correct
111 Correct 96 ms 10360 KB Output is correct
112 Correct 6 ms 384 KB Output is correct
113 Correct 111 ms 13304 KB Output is correct
114 Incorrect 25 ms 6016 KB Output isn't correct
115 Halted 0 ms 0 KB -