답안 #1035323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035323 2024-07-26T09:23:29 Z c2zi6 꿈 (IOI13_dreaming) C++14
47 / 100
46 ms 16860 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;*/
    }

    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 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:94:33: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   94 |         int diameter = distd1[d2];
      |                                 ^
dreaming.cpp:90:12: warning: 'ret' may be used uninitialized in this function [-Wmaybe-uninitialized]
   90 |         dfs(d1, -1, distd1);
      |         ~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 15324 KB Output is correct
2 Correct 30 ms 15112 KB Output is correct
3 Correct 19 ms 10200 KB Output is correct
4 Correct 4 ms 2632 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 9 ms 3672 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 17 ms 5868 KB Output is correct
9 Correct 23 ms 8000 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 33 ms 10628 KB Output is correct
12 Correct 38 ms 12752 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 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 0 ms 348 KB Output is correct
11 Correct 0 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 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 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 15324 KB Output is correct
2 Correct 30 ms 15112 KB Output is correct
3 Correct 19 ms 10200 KB Output is correct
4 Correct 4 ms 2632 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 9 ms 3672 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 17 ms 5868 KB Output is correct
9 Correct 23 ms 8000 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 33 ms 10628 KB Output is correct
12 Correct 38 ms 12752 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 1 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 1 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 0 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 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 348 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 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 33 ms 15312 KB Output is correct
40 Correct 31 ms 15260 KB Output is correct
41 Correct 22 ms 10200 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 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 376 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 42 ms 11492 KB Output is correct
58 Correct 38 ms 11480 KB Output is correct
59 Correct 46 ms 11352 KB Output is correct
60 Correct 39 ms 11212 KB Output is correct
61 Correct 38 ms 11472 KB Output is correct
62 Correct 37 ms 11348 KB Output is correct
63 Correct 39 ms 10976 KB Output is correct
64 Correct 35 ms 10972 KB Output is correct
65 Correct 35 ms 11476 KB Output is correct
66 Correct 37 ms 11392 KB Output is correct
67 Correct 40 ms 11216 KB Output is correct
68 Correct 38 ms 11300 KB Output is correct
69 Correct 40 ms 11496 KB Output is correct
70 Correct 41 ms 11468 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 616 KB Output is correct
74 Correct 1 ms 716 KB Output is correct
75 Correct 1 ms 600 KB Output is correct
76 Correct 1 ms 712 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 42 ms 11476 KB Output is correct
81 Correct 40 ms 11216 KB Output is correct
82 Correct 37 ms 11472 KB Output is correct
83 Correct 37 ms 11468 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 448 KB Output is correct
86 Correct 1 ms 492 KB Output is correct
87 Correct 1 ms 600 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 1 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 444 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 348 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 0 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 9 ms 3672 KB Output is correct
106 Correct 1 ms 348 KB Output is correct
107 Correct 17 ms 5980 KB Output is correct
108 Correct 23 ms 7900 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 30 ms 10704 KB Output is correct
111 Correct 35 ms 12760 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 46 ms 16860 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 18 ms 10256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 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 1 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 0 ms 348 KB Output is correct
11 Correct 0 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 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 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Incorrect 1 ms 600 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 15324 KB Output is correct
2 Correct 30 ms 15112 KB Output is correct
3 Correct 19 ms 10200 KB Output is correct
4 Correct 4 ms 2632 KB Output is correct
5 Correct 4 ms 1628 KB Output is correct
6 Correct 9 ms 3672 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 17 ms 5868 KB Output is correct
9 Correct 23 ms 8000 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 33 ms 10628 KB Output is correct
12 Correct 38 ms 12752 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 1 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 1 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 0 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 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 348 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 348 KB Output is correct
33 Correct 1 ms 348 KB Output is correct
34 Correct 0 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 0 ms 348 KB Output is correct
37 Correct 0 ms 344 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 33 ms 15312 KB Output is correct
40 Correct 31 ms 15260 KB Output is correct
41 Correct 22 ms 10200 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 348 KB Output is correct
45 Correct 1 ms 348 KB Output is correct
46 Correct 0 ms 348 KB Output is correct
47 Correct 0 ms 344 KB Output is correct
48 Correct 0 ms 348 KB Output is correct
49 Correct 0 ms 348 KB Output is correct
50 Correct 0 ms 348 KB Output is correct
51 Correct 0 ms 348 KB Output is correct
52 Correct 0 ms 348 KB Output is correct
53 Correct 0 ms 348 KB Output is correct
54 Correct 0 ms 376 KB Output is correct
55 Correct 0 ms 348 KB Output is correct
56 Correct 0 ms 348 KB Output is correct
57 Correct 42 ms 11492 KB Output is correct
58 Correct 38 ms 11480 KB Output is correct
59 Correct 46 ms 11352 KB Output is correct
60 Correct 39 ms 11212 KB Output is correct
61 Correct 38 ms 11472 KB Output is correct
62 Correct 37 ms 11348 KB Output is correct
63 Correct 39 ms 10976 KB Output is correct
64 Correct 35 ms 10972 KB Output is correct
65 Correct 35 ms 11476 KB Output is correct
66 Correct 37 ms 11392 KB Output is correct
67 Correct 40 ms 11216 KB Output is correct
68 Correct 38 ms 11300 KB Output is correct
69 Correct 40 ms 11496 KB Output is correct
70 Correct 41 ms 11468 KB Output is correct
71 Correct 0 ms 348 KB Output is correct
72 Correct 1 ms 604 KB Output is correct
73 Correct 1 ms 616 KB Output is correct
74 Correct 1 ms 716 KB Output is correct
75 Correct 1 ms 600 KB Output is correct
76 Correct 1 ms 712 KB Output is correct
77 Correct 1 ms 604 KB Output is correct
78 Correct 1 ms 604 KB Output is correct
79 Correct 1 ms 604 KB Output is correct
80 Correct 42 ms 11476 KB Output is correct
81 Correct 40 ms 11216 KB Output is correct
82 Correct 37 ms 11472 KB Output is correct
83 Correct 37 ms 11468 KB Output is correct
84 Correct 1 ms 600 KB Output is correct
85 Correct 1 ms 448 KB Output is correct
86 Correct 1 ms 492 KB Output is correct
87 Correct 1 ms 600 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 1 ms 604 KB Output is correct
93 Correct 1 ms 604 KB Output is correct
94 Correct 0 ms 444 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 348 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 0 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 9 ms 3672 KB Output is correct
106 Correct 1 ms 348 KB Output is correct
107 Correct 17 ms 5980 KB Output is correct
108 Correct 23 ms 7900 KB Output is correct
109 Correct 1 ms 348 KB Output is correct
110 Correct 30 ms 10704 KB Output is correct
111 Correct 35 ms 12760 KB Output is correct
112 Correct 1 ms 348 KB Output is correct
113 Correct 46 ms 16860 KB Output is correct
114 Incorrect 18 ms 10256 KB Output isn't correct
115 Halted 0 ms 0 KB -