Submission #1035338

# Submission time Handle Problem Language Result Execution time Memory
1035338 2024-07-26T09:35:18 Z c2zi6 Dreaming (IOI13_dreaming) C++14
47 / 100
61 ms 17072 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "dreaming.h"

int n, m, L;
VVPI gp;
void dfs(int u, int p, VI& dist, VI& comp) {
    comp.pb(u);
    for (auto[v, w] : gp[u]) if (v != p) {
        dist[v] = dist[u] + w;
        dfs(v, u, dist, comp);
    }
}
void dfs(int u, int p, VI& dist) {
    for (auto[v, w] : gp[u]) if (v != p) {
        dist[v] = dist[u] + w;
        dfs(v, u, dist);
    }
}

int amenaheru(VI& comp, VI& dist) {
    int ret;
    int mx = -2e9;
    for (int u : comp) if (dist[u] > mx) {
        ret = u;
        mx = dist[u];
    }
    return ret;
}
int amenamejtex(VI& comp, VI& maxdist) {
    int ret = 2e9;
    for (int u : comp) setmin(ret, maxdist[u]);
    return ret;
}

int travelTime(int N, int M, int L_arg, int A[], int B[], int T[]) {
    n = N;
    m = M;
    L = L_arg;
    gp = VVPI(n);
    rep(i, m) {
        int u = A[i];
        int v = B[i];
        int w = T[i];
        gp[u].pb({v, w});
        gp[v].pb({u, w});
    }

    VI dist(n, 2e9);
    VI distd1(n);
    VI distd2(n);
    VI maxdist(n);
    int answer = 0;
    VVI comp;
    rep(u, n) if (dist[u] == 2e9) {
        dist[u] = 0;
        comp.pb(VI());
        dfs(u, -1, dist, comp.back());
        int d1 = amenaheru(comp.back(), dist);
        dfs(d1, -1, distd1);
        int d2 = amenaheru(comp.back(), distd1);
        dfs(d2, -1, distd2);
        for (int u : comp.back()) maxdist[u] = max(distd1[u], distd2[u]);
        int diameter = distd1[d2];
        setmax(answer, diameter);
        /*cout << "COMPONENT: ";*/
        /*for (int u : comp.back()) cout << u << " "; cout << endl;*/
        /*cout << "DIAMETER: " << d1 << " " << d2 << " " << distd1[d2] << endl;*/
        /*cout << "FARTHEST PATH LENGTH FROM " << endl;*/
        /*for (int u : comp.back()) {*/
        /*    cout << u << ": " << maxdist[u] << endl;*/
        /*}*/
        /*cout << endl;*/
    }

    if (comp.size() > 2) {
        VI a(3, 0);
        rep(u, n) for (auto[v, w] : gp[u]) {
            if (u < v) a.pb(w);
        }
        sort(all(a));
        reverse(all(a));
        VI b;
        b.pb(a[0]);
        b.pb(a[1]+L);
        b.pb(a[2]+L);
        sort(all(b));
        reverse(all(b));
        return b[0] + b[1];
    }

    int ans = 0;
    for (VI& c : comp) {
        ans += amenamejtex(c, maxdist);
    }
    setmax(answer, ans + L);

    return answer;
}







Compilation message

dreaming.cpp: In function 'void dfs(int, int, VI&, VI&)':
dreaming.cpp:38:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   38 |     for (auto[v, w] : gp[u]) if (v != p) {
      |              ^
dreaming.cpp: In function 'void dfs(int, int, VI&)':
dreaming.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |     for (auto[v, w] : gp[u]) if (v != p) {
      |              ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:107:28: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
  107 |         rep(u, n) for (auto[v, w] : gp[u]) {
      |                            ^
dreaming.cpp: In function 'int amenaheru(VI&, VI&)':
dreaming.cpp:57:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   57 |     return ret;
      |            ^~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:93:33: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   93 |         int diameter = distd1[d2];
      |                                 ^
dreaming.cpp:89:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |         dfs(d1, -1, distd1);
      |         ~~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 32 ms 15240 KB Output is correct
2 Correct 61 ms 15312 KB Output is correct
3 Correct 23 ms 10184 KB Output is correct
4 Correct 5 ms 2652 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 9 ms 3676 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 17 ms 5956 KB Output is correct
9 Correct 21 ms 7900 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 33 ms 10684 KB Output is correct
12 Correct 41 ms 12764 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 32 ms 15240 KB Output is correct
2 Correct 61 ms 15312 KB Output is correct
3 Correct 23 ms 10184 KB Output is correct
4 Correct 5 ms 2652 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 9 ms 3676 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 17 ms 5956 KB Output is correct
9 Correct 21 ms 7900 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 33 ms 10684 KB Output is correct
12 Correct 41 ms 12764 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 440 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 42 ms 15316 KB Output is correct
40 Correct 43 ms 15108 KB Output is correct
41 Correct 22 ms 10196 KB Output is correct
42 Correct 5 ms 2652 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 440 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 436 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 46 ms 11448 KB Output is correct
58 Correct 40 ms 11480 KB Output is correct
59 Correct 43 ms 11216 KB Output is correct
60 Correct 42 ms 11212 KB Output is correct
61 Correct 43 ms 11340 KB Output is correct
62 Correct 43 ms 11356 KB Output is correct
63 Correct 35 ms 11144 KB Output is correct
64 Correct 35 ms 10968 KB Output is correct
65 Correct 35 ms 11476 KB Output is correct
66 Correct 36 ms 11484 KB Output is correct
67 Correct 40 ms 11220 KB Output is correct
68 Correct 39 ms 11216 KB Output is correct
69 Correct 41 ms 11600 KB Output is correct
70 Correct 42 ms 11480 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 756 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 764 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 41 ms 11504 KB Output is correct
81 Correct 39 ms 11216 KB Output is correct
82 Correct 38 ms 11460 KB Output is correct
83 Correct 39 ms 11468 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 688 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 2 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 600 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 1 ms 348 KB Output is correct
103 Correct 0 ms 348 KB Output is correct
104 Correct 4 ms 1628 KB Output is correct
105 Correct 12 ms 3828 KB Output is correct
106 Correct 1 ms 348 KB Output is correct
107 Correct 19 ms 5980 KB Output is correct
108 Correct 27 ms 7992 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 31 ms 10548 KB Output is correct
111 Correct 35 ms 12764 KB Output is correct
112 Correct 1 ms 344 KB Output is correct
113 Correct 46 ms 17072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 10400 KB Output is correct
2 Correct 19 ms 10512 KB Output is correct
3 Correct 22 ms 10564 KB Output is correct
4 Correct 22 ms 10496 KB Output is correct
5 Correct 25 ms 10508 KB Output is correct
6 Correct 20 ms 12304 KB Output is correct
7 Correct 23 ms 11020 KB Output is correct
8 Correct 18 ms 10340 KB Output is correct
9 Correct 21 ms 10252 KB Output is correct
10 Correct 23 ms 10756 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 9 ms 9876 KB Output is correct
13 Correct 12 ms 9920 KB Output is correct
14 Correct 9 ms 9740 KB Output is correct
15 Correct 9 ms 9748 KB Output is correct
16 Correct 9 ms 9740 KB Output is correct
17 Correct 10 ms 9736 KB Output is correct
18 Correct 10 ms 9740 KB Output is correct
19 Correct 10 ms 9628 KB Output is correct
20 Incorrect 0 ms 348 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 344 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 440 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Incorrect 1 ms 348 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 15240 KB Output is correct
2 Correct 61 ms 15312 KB Output is correct
3 Correct 23 ms 10184 KB Output is correct
4 Correct 5 ms 2652 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 9 ms 3676 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 17 ms 5956 KB Output is correct
9 Correct 21 ms 7900 KB Output is correct
10 Correct 0 ms 344 KB Output is correct
11 Correct 33 ms 10684 KB Output is correct
12 Correct 41 ms 12764 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 348 KB Output is correct
29 Correct 0 ms 344 KB Output is correct
30 Correct 0 ms 348 KB Output is correct
31 Correct 0 ms 348 KB Output is correct
32 Correct 0 ms 440 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 0 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 0 ms 348 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 42 ms 15316 KB Output is correct
40 Correct 43 ms 15108 KB Output is correct
41 Correct 22 ms 10196 KB Output is correct
42 Correct 5 ms 2652 KB Output is correct
43 Correct 0 ms 348 KB Output is correct
44 Correct 0 ms 440 KB Output is correct
45 Correct 0 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 348 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 1 ms 344 KB Output is correct
51 Correct 0 ms 344 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 436 KB Output is correct
54 Correct 0 ms 348 KB Output is correct
55 Correct 1 ms 348 KB Output is correct
56 Correct 0 ms 344 KB Output is correct
57 Correct 46 ms 11448 KB Output is correct
58 Correct 40 ms 11480 KB Output is correct
59 Correct 43 ms 11216 KB Output is correct
60 Correct 42 ms 11212 KB Output is correct
61 Correct 43 ms 11340 KB Output is correct
62 Correct 43 ms 11356 KB Output is correct
63 Correct 35 ms 11144 KB Output is correct
64 Correct 35 ms 10968 KB Output is correct
65 Correct 35 ms 11476 KB Output is correct
66 Correct 36 ms 11484 KB Output is correct
67 Correct 40 ms 11220 KB Output is correct
68 Correct 39 ms 11216 KB Output is correct
69 Correct 41 ms 11600 KB Output is correct
70 Correct 42 ms 11480 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 756 KB Output is correct
73 Correct 1 ms 604 KB Output is correct
74 Correct 1 ms 604 KB Output is correct
75 Correct 1 ms 604 KB Output is correct
76 Correct 1 ms 604 KB Output is correct
77 Correct 1 ms 764 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 41 ms 11504 KB Output is correct
81 Correct 39 ms 11216 KB Output is correct
82 Correct 38 ms 11460 KB Output is correct
83 Correct 39 ms 11468 KB Output is correct
84 Correct 1 ms 604 KB Output is correct
85 Correct 1 ms 604 KB Output is correct
86 Correct 1 ms 604 KB Output is correct
87 Correct 1 ms 688 KB Output is correct
88 Correct 1 ms 604 KB Output is correct
89 Correct 1 ms 604 KB Output is correct
90 Correct 1 ms 604 KB Output is correct
91 Correct 1 ms 604 KB Output is correct
92 Correct 2 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 348 KB Output is correct
95 Correct 0 ms 348 KB Output is correct
96 Correct 0 ms 348 KB Output is correct
97 Correct 0 ms 600 KB Output is correct
98 Correct 0 ms 348 KB Output is correct
99 Correct 0 ms 348 KB Output is correct
100 Correct 0 ms 348 KB Output is correct
101 Correct 0 ms 348 KB Output is correct
102 Correct 1 ms 348 KB Output is correct
103 Correct 0 ms 348 KB Output is correct
104 Correct 4 ms 1628 KB Output is correct
105 Correct 12 ms 3828 KB Output is correct
106 Correct 1 ms 348 KB Output is correct
107 Correct 19 ms 5980 KB Output is correct
108 Correct 27 ms 7992 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 31 ms 10548 KB Output is correct
111 Correct 35 ms 12764 KB Output is correct
112 Correct 1 ms 344 KB Output is correct
113 Correct 46 ms 17072 KB Output is correct
114 Correct 22 ms 10400 KB Output is correct
115 Correct 19 ms 10512 KB Output is correct
116 Correct 22 ms 10564 KB Output is correct
117 Correct 22 ms 10496 KB Output is correct
118 Correct 25 ms 10508 KB Output is correct
119 Correct 20 ms 12304 KB Output is correct
120 Correct 23 ms 11020 KB Output is correct
121 Correct 18 ms 10340 KB Output is correct
122 Correct 21 ms 10252 KB Output is correct
123 Correct 23 ms 10756 KB Output is correct
124 Correct 0 ms 348 KB Output is correct
125 Correct 9 ms 9876 KB Output is correct
126 Correct 12 ms 9920 KB Output is correct
127 Correct 9 ms 9740 KB Output is correct
128 Correct 9 ms 9748 KB Output is correct
129 Correct 9 ms 9740 KB Output is correct
130 Correct 10 ms 9736 KB Output is correct
131 Correct 10 ms 9740 KB Output is correct
132 Correct 10 ms 9628 KB Output is correct
133 Incorrect 0 ms 348 KB Output isn't correct
134 Halted 0 ms 0 KB -