답안 #1035359

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1035359 2024-07-26T09:50:47 Z c2zi6 꿈 (IOI13_dreaming) C++14
14 / 100
42 ms 15336 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 globald = 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(globald, 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];*/
    /*}*/

    VI mid;
    for (VI& c : comp) {
        mid.pb(amenamejtex(c, maxdist));
    }

    int answer = 2e9;

    int mxi;
    int mx = 0;
    rep(i, comp.size()) {
        if (mid[i] > mx) {
            mxi = i;
            mx = mid[i];
        }
    }

    replr(i, mxi, mxi) {
        int diameter = globald;

        VI children;
        children.pb(0);
        children.pb(mid[i]);
        rep(j, comp.size()) if (j != i) {
            children.pb(mid[j] + L);
        }
        sort(all(children));
        reverse(all(children));
        
        setmax(diameter, children[0] + children[1]);
        /*cout << "IF THE CENTER IS " << i << ", THE DIAMETER IS " << diameter << endl;*/
        setmin(answer, diameter);
    }


    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:143:29: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
  143 |         rep(j, comp.size()) if (j != i) {
      |                             ^~
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);
      |         ~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 15336 KB Output is correct
2 Correct 35 ms 15148 KB Output is correct
3 Correct 23 ms 10200 KB Output is correct
4 Correct 5 ms 2652 KB Output is correct
5 Correct 6 ms 1596 KB Output is correct
6 Correct 15 ms 3736 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 26 ms 6056 KB Output is correct
9 Correct 24 ms 7900 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 34 ms 10512 KB Output is correct
12 Correct 42 ms 12848 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 1 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 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Runtime error 1 ms 348 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 15336 KB Output is correct
2 Correct 35 ms 15148 KB Output is correct
3 Correct 23 ms 10200 KB Output is correct
4 Correct 5 ms 2652 KB Output is correct
5 Correct 6 ms 1596 KB Output is correct
6 Correct 15 ms 3736 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 26 ms 6056 KB Output is correct
9 Correct 24 ms 7900 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 34 ms 10512 KB Output is correct
12 Correct 42 ms 12848 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 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 344 KB Output is correct
21 Correct 1 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 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Runtime error 1 ms 348 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 10984 KB Output is correct
2 Correct 39 ms 10828 KB Output is correct
3 Correct 19 ms 11024 KB Output is correct
4 Correct 29 ms 11084 KB Output is correct
5 Correct 26 ms 10772 KB Output is correct
6 Correct 38 ms 12292 KB Output is correct
7 Correct 33 ms 11372 KB Output is correct
8 Correct 19 ms 10820 KB Output is correct
9 Correct 21 ms 10584 KB Output is correct
10 Correct 20 ms 11280 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 20 ms 11020 KB Output is correct
13 Correct 17 ms 11016 KB Output is correct
14 Correct 21 ms 10968 KB Output is correct
15 Correct 12 ms 11020 KB Output is correct
16 Correct 12 ms 11020 KB Output is correct
17 Correct 12 ms 10928 KB Output is correct
18 Correct 13 ms 11016 KB Output is correct
19 Correct 14 ms 11020 KB Output is correct
20 Runtime error 1 ms 344 KB Execution killed with signal 11
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 448 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 344 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 344 KB Output is correct
8 Correct 1 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 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Runtime error 1 ms 348 KB Execution killed with signal 11
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 36 ms 15336 KB Output is correct
2 Correct 35 ms 15148 KB Output is correct
3 Correct 23 ms 10200 KB Output is correct
4 Correct 5 ms 2652 KB Output is correct
5 Correct 6 ms 1596 KB Output is correct
6 Correct 15 ms 3736 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 26 ms 6056 KB Output is correct
9 Correct 24 ms 7900 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 34 ms 10512 KB Output is correct
12 Correct 42 ms 12848 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 0 ms 448 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 344 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 344 KB Output is correct
21 Correct 1 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 1 ms 344 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Runtime error 1 ms 348 KB Execution killed with signal 11
29 Halted 0 ms 0 KB -