Submission #478696

# Submission time Handle Problem Language Result Execution time Memory
478696 2021-10-08T07:24:19 Z VitaliyFS Dreaming (IOI13_dreaming) C++17
47 / 100
133 ms 20656 KB
#include "dreaming.h"
#include <bits/stdc++.h>

#define fr first
#define sc second
 
using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
//typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> myset;
 
const ll DIM = 100007, INF = 2000000000000000007, MOD = 998244353, split = 1000;
 
ll t, n, m, z, q, nn,mm,kk, par[DIM], di[DIM], cl, cr, f, prev, mid, p, res2, nComp = 0, ans1, ans2, res, mi, pos, pos1, pos2, sum, ct, y, k, tt, x, t1, t2, mi1 = INF, ma1 = -INF, mi2 = INF, ma2 = -INF, v, l = INF, r = -INF, u, w, ma = -INF, id, lx, xd, yd;
bool flag;
int A[DIM], B[DIM], T[DIM];
pll comp[DIM];
vector<pll> g[DIM];
vector<ll> usedVertex;
bool used[DIM];

void dfs(ll v, ll p = -1, ll dp = 0, ll d = 0) {
    usedVertex.push_back(v);
    if(d > ma) {ma = max(ma, d); u = v;}
    used[v] = 1;
    di[v] = dp;
    par[v] = p;
    for(auto [u, w] : g[v])
        if(!used[u]) {dfs(u, v, w, d + w); z+=w;}
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;++i) {
        g[A[i]].push_back({B[i], T[i]});
        g[B[i]].push_back({A[i], T[i]});
    }
    l = 0;
    for(int i =0;i<N;++i){
        if(!used[i]) {
            l++;
            usedVertex.clear();
            u = i, ma = 0, z = 0;
            dfs(i);
            for(auto u : usedVertex) used[u] = 0;
            ma = 0;
            dfs(u);
            k = 0; res = abs(ma - k); f =  u;
            while(par[u] != -1) {
                k += di[u];
                ma -= di[u];
                u = par[u];
                if(abs(k - ma) < res) {f = u; res = abs(k - ma);}
            }
            comp[l] = {f, z};

        }
    }
    f = comp[1].fr, z = comp[1].sc;
    for(int i=2;i<=l;++i){
        g[f].push_back({comp[i].fr, L});
        g[comp[i].fr].push_back({f, L});
        if(z < comp[i].sc) {f = comp[i].fr;}
        z += comp[i].sc + L;
    }
    for(int i = 0;i<N;++i) used[i] = 0;
    u = 0; ma = 0;
    dfs(u);
    for(int i=0;i<N;++i)used[i]=0;
    ma = 0, dfs(u);
    return ma;
}
# Verdict Execution time Memory Grader output
1 Correct 69 ms 16820 KB Output is correct
2 Correct 65 ms 17968 KB Output is correct
3 Correct 43 ms 12888 KB Output is correct
4 Correct 10 ms 4944 KB Output is correct
5 Correct 9 ms 4384 KB Output is correct
6 Correct 16 ms 6344 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 32 ms 9088 KB Output is correct
9 Correct 44 ms 10980 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 73 ms 14592 KB Output is correct
12 Correct 95 ms 16360 KB Output is correct
13 Correct 2 ms 2768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2660 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2664 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2664 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 69 ms 16820 KB Output is correct
2 Correct 65 ms 17968 KB Output is correct
3 Correct 43 ms 12888 KB Output is correct
4 Correct 10 ms 4944 KB Output is correct
5 Correct 9 ms 4384 KB Output is correct
6 Correct 16 ms 6344 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 32 ms 9088 KB Output is correct
9 Correct 44 ms 10980 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 73 ms 14592 KB Output is correct
12 Correct 95 ms 16360 KB Output is correct
13 Correct 2 ms 2768 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2660 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2664 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2664 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2656 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2640 KB Output is correct
37 Correct 2 ms 2640 KB Output is correct
38 Correct 2 ms 2668 KB Output is correct
39 Correct 70 ms 17996 KB Output is correct
40 Correct 65 ms 17908 KB Output is correct
41 Correct 43 ms 12860 KB Output is correct
42 Correct 10 ms 5000 KB Output is correct
43 Correct 2 ms 2640 KB Output is correct
44 Correct 2 ms 2664 KB Output is correct
45 Correct 2 ms 2640 KB Output is correct
46 Correct 2 ms 2660 KB Output is correct
47 Correct 2 ms 2656 KB Output is correct
48 Correct 2 ms 2640 KB Output is correct
49 Correct 2 ms 2640 KB Output is correct
50 Correct 2 ms 2640 KB Output is correct
51 Correct 3 ms 2640 KB Output is correct
52 Correct 2 ms 2660 KB Output is correct
53 Correct 2 ms 2640 KB Output is correct
54 Correct 2 ms 2640 KB Output is correct
55 Correct 2 ms 2660 KB Output is correct
56 Correct 2 ms 2640 KB Output is correct
57 Correct 105 ms 14816 KB Output is correct
58 Correct 112 ms 16956 KB Output is correct
59 Correct 107 ms 14656 KB Output is correct
60 Correct 108 ms 16692 KB Output is correct
61 Correct 94 ms 14524 KB Output is correct
62 Correct 105 ms 16568 KB Output is correct
63 Correct 95 ms 14168 KB Output is correct
64 Correct 98 ms 14140 KB Output is correct
65 Correct 100 ms 14344 KB Output is correct
66 Correct 99 ms 14376 KB Output is correct
67 Correct 105 ms 14536 KB Output is correct
68 Correct 121 ms 14712 KB Output is correct
69 Correct 115 ms 16900 KB Output is correct
70 Correct 116 ms 16912 KB Output is correct
71 Correct 2 ms 2640 KB Output is correct
72 Correct 4 ms 3152 KB Output is correct
73 Correct 4 ms 3152 KB Output is correct
74 Correct 3 ms 3024 KB Output is correct
75 Correct 4 ms 3152 KB Output is correct
76 Correct 3 ms 3024 KB Output is correct
77 Correct 3 ms 3024 KB Output is correct
78 Correct 4 ms 3180 KB Output is correct
79 Correct 3 ms 3024 KB Output is correct
80 Correct 105 ms 16668 KB Output is correct
81 Correct 108 ms 14612 KB Output is correct
82 Correct 94 ms 14576 KB Output is correct
83 Correct 96 ms 14596 KB Output is correct
84 Correct 3 ms 2896 KB Output is correct
85 Correct 3 ms 2896 KB Output is correct
86 Correct 3 ms 3024 KB Output is correct
87 Correct 3 ms 3024 KB Output is correct
88 Correct 3 ms 3024 KB Output is correct
89 Correct 3 ms 2928 KB Output is correct
90 Correct 3 ms 3024 KB Output is correct
91 Correct 3 ms 3024 KB Output is correct
92 Correct 3 ms 3024 KB Output is correct
93 Correct 4 ms 3024 KB Output is correct
94 Correct 2 ms 2640 KB Output is correct
95 Correct 2 ms 2656 KB Output is correct
96 Correct 2 ms 2640 KB Output is correct
97 Correct 2 ms 2640 KB Output is correct
98 Correct 2 ms 2640 KB Output is correct
99 Correct 2 ms 2640 KB Output is correct
100 Correct 2 ms 2640 KB Output is correct
101 Correct 2 ms 2640 KB Output is correct
102 Correct 2 ms 2640 KB Output is correct
103 Correct 2 ms 2640 KB Output is correct
104 Correct 8 ms 4340 KB Output is correct
105 Correct 16 ms 6260 KB Output is correct
106 Correct 2 ms 2640 KB Output is correct
107 Correct 36 ms 9064 KB Output is correct
108 Correct 44 ms 10948 KB Output is correct
109 Correct 2 ms 2768 KB Output is correct
110 Correct 75 ms 14476 KB Output is correct
111 Correct 91 ms 16188 KB Output is correct
112 Correct 2 ms 2768 KB Output is correct
113 Correct 133 ms 20656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 41 ms 12156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2636 KB Output is correct
2 Correct 2 ms 2660 KB Output is correct
3 Correct 2 ms 2640 KB Output is correct
4 Correct 2 ms 2640 KB Output is correct
5 Correct 2 ms 2664 KB Output is correct
6 Correct 2 ms 2640 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 2 ms 2664 KB Output is correct
9 Correct 2 ms 2640 KB Output is correct
10 Correct 2 ms 2640 KB Output is correct
11 Correct 2 ms 2640 KB Output is correct
12 Correct 2 ms 2640 KB Output is correct
13 Correct 2 ms 2640 KB Output is correct
14 Correct 2 ms 2640 KB Output is correct
15 Correct 2 ms 2640 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2640 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2656 KB Output is correct
21 Correct 2 ms 2640 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2668 KB Output is correct
26 Correct 2 ms 2768 KB Output is correct
27 Correct 3 ms 2896 KB Output is correct
28 Correct 3 ms 3024 KB Output is correct
29 Correct 2 ms 2768 KB Output is correct
30 Correct 3 ms 2896 KB Output is correct
31 Correct 3 ms 3024 KB Output is correct
32 Correct 2 ms 2768 KB Output is correct
33 Incorrect 2 ms 2896 KB Output isn't correct
34 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 69 ms 16820 KB Output is correct
2 Correct 65 ms 17968 KB Output is correct
3 Correct 43 ms 12888 KB Output is correct
4 Correct 10 ms 4944 KB Output is correct
5 Correct 9 ms 4384 KB Output is correct
6 Correct 16 ms 6344 KB Output is correct
7 Correct 2 ms 2640 KB Output is correct
8 Correct 32 ms 9088 KB Output is correct
9 Correct 44 ms 10980 KB Output is correct
10 Correct 2 ms 2768 KB Output is correct
11 Correct 73 ms 14592 KB Output is correct
12 Correct 95 ms 16360 KB Output is correct
13 Correct 2 ms 2768 KB Output is correct
14 Correct 2 ms 2636 KB Output is correct
15 Correct 2 ms 2660 KB Output is correct
16 Correct 2 ms 2640 KB Output is correct
17 Correct 2 ms 2640 KB Output is correct
18 Correct 2 ms 2664 KB Output is correct
19 Correct 2 ms 2640 KB Output is correct
20 Correct 2 ms 2640 KB Output is correct
21 Correct 2 ms 2664 KB Output is correct
22 Correct 2 ms 2640 KB Output is correct
23 Correct 2 ms 2640 KB Output is correct
24 Correct 2 ms 2640 KB Output is correct
25 Correct 2 ms 2640 KB Output is correct
26 Correct 2 ms 2640 KB Output is correct
27 Correct 2 ms 2640 KB Output is correct
28 Correct 2 ms 2640 KB Output is correct
29 Correct 2 ms 2640 KB Output is correct
30 Correct 2 ms 2640 KB Output is correct
31 Correct 2 ms 2640 KB Output is correct
32 Correct 2 ms 2640 KB Output is correct
33 Correct 2 ms 2656 KB Output is correct
34 Correct 2 ms 2640 KB Output is correct
35 Correct 2 ms 2640 KB Output is correct
36 Correct 2 ms 2640 KB Output is correct
37 Correct 2 ms 2640 KB Output is correct
38 Correct 2 ms 2668 KB Output is correct
39 Correct 70 ms 17996 KB Output is correct
40 Correct 65 ms 17908 KB Output is correct
41 Correct 43 ms 12860 KB Output is correct
42 Correct 10 ms 5000 KB Output is correct
43 Correct 2 ms 2640 KB Output is correct
44 Correct 2 ms 2664 KB Output is correct
45 Correct 2 ms 2640 KB Output is correct
46 Correct 2 ms 2660 KB Output is correct
47 Correct 2 ms 2656 KB Output is correct
48 Correct 2 ms 2640 KB Output is correct
49 Correct 2 ms 2640 KB Output is correct
50 Correct 2 ms 2640 KB Output is correct
51 Correct 3 ms 2640 KB Output is correct
52 Correct 2 ms 2660 KB Output is correct
53 Correct 2 ms 2640 KB Output is correct
54 Correct 2 ms 2640 KB Output is correct
55 Correct 2 ms 2660 KB Output is correct
56 Correct 2 ms 2640 KB Output is correct
57 Correct 105 ms 14816 KB Output is correct
58 Correct 112 ms 16956 KB Output is correct
59 Correct 107 ms 14656 KB Output is correct
60 Correct 108 ms 16692 KB Output is correct
61 Correct 94 ms 14524 KB Output is correct
62 Correct 105 ms 16568 KB Output is correct
63 Correct 95 ms 14168 KB Output is correct
64 Correct 98 ms 14140 KB Output is correct
65 Correct 100 ms 14344 KB Output is correct
66 Correct 99 ms 14376 KB Output is correct
67 Correct 105 ms 14536 KB Output is correct
68 Correct 121 ms 14712 KB Output is correct
69 Correct 115 ms 16900 KB Output is correct
70 Correct 116 ms 16912 KB Output is correct
71 Correct 2 ms 2640 KB Output is correct
72 Correct 4 ms 3152 KB Output is correct
73 Correct 4 ms 3152 KB Output is correct
74 Correct 3 ms 3024 KB Output is correct
75 Correct 4 ms 3152 KB Output is correct
76 Correct 3 ms 3024 KB Output is correct
77 Correct 3 ms 3024 KB Output is correct
78 Correct 4 ms 3180 KB Output is correct
79 Correct 3 ms 3024 KB Output is correct
80 Correct 105 ms 16668 KB Output is correct
81 Correct 108 ms 14612 KB Output is correct
82 Correct 94 ms 14576 KB Output is correct
83 Correct 96 ms 14596 KB Output is correct
84 Correct 3 ms 2896 KB Output is correct
85 Correct 3 ms 2896 KB Output is correct
86 Correct 3 ms 3024 KB Output is correct
87 Correct 3 ms 3024 KB Output is correct
88 Correct 3 ms 3024 KB Output is correct
89 Correct 3 ms 2928 KB Output is correct
90 Correct 3 ms 3024 KB Output is correct
91 Correct 3 ms 3024 KB Output is correct
92 Correct 3 ms 3024 KB Output is correct
93 Correct 4 ms 3024 KB Output is correct
94 Correct 2 ms 2640 KB Output is correct
95 Correct 2 ms 2656 KB Output is correct
96 Correct 2 ms 2640 KB Output is correct
97 Correct 2 ms 2640 KB Output is correct
98 Correct 2 ms 2640 KB Output is correct
99 Correct 2 ms 2640 KB Output is correct
100 Correct 2 ms 2640 KB Output is correct
101 Correct 2 ms 2640 KB Output is correct
102 Correct 2 ms 2640 KB Output is correct
103 Correct 2 ms 2640 KB Output is correct
104 Correct 8 ms 4340 KB Output is correct
105 Correct 16 ms 6260 KB Output is correct
106 Correct 2 ms 2640 KB Output is correct
107 Correct 36 ms 9064 KB Output is correct
108 Correct 44 ms 10948 KB Output is correct
109 Correct 2 ms 2768 KB Output is correct
110 Correct 75 ms 14476 KB Output is correct
111 Correct 91 ms 16188 KB Output is correct
112 Correct 2 ms 2768 KB Output is correct
113 Correct 133 ms 20656 KB Output is correct
114 Incorrect 41 ms 12156 KB Output isn't correct
115 Halted 0 ms 0 KB -