답안 #730972

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
730972 2023-04-26T17:17:53 Z Desh03 꿈 (IOI13_dreaming) C++17
18 / 100
112 ms 21192 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

vector<vector<pair<int, int>>> g;
vector<bool> vis;
int ans;

void calcd(int u, int p, int d_, vector<pair<int, int>> &a) {
    vis[u] = 1;
    a.push_back({u, d_});
    for (auto [v, w] : g[u])
        if (v ^ p)
            calcd(v, u, d_ + w, a);
}

void getmax(int x) {
    vector<pair<int, int>> d, d2;
    calcd(x, x, 0, d);
    int mx = -1, mxn;
    for (auto [a, b] : d)
        if (b > mx) mx = b, mxn = a;
    d.clear();
    calcd(mxn, mxn, 0, d);
    int mx2 = -1, mxn2;
    map<int, int> dd;
    for (auto [a, b] : d) {
        dd[a] = b;
        if (b > mx2) mx2 = b, mxn2 = a;
    }
    calcd(mxn2, mxn2, 0, d2);
    for (auto [a, b] : d2)
        ans = min(ans, max(b, dd[a]));
}

int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
    g.resize(n), vis.resize(n);
    for (int i = 0; i < m; i++) {
        int u = a[i], v = b[i], w = t[i];
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    vector<int> mx;
    for (int i = 0; i < n; i++)
        if (!vis[i]) {
            ans = 2e9;
            getmax(i);
            mx.push_back(ans);
        }
    sort(mx.rbegin(), mx.rend());
    return mx.size() == 1 ? mx[0] : mx.size() == 2 ? mx[0] + mx[1] + l : max(mx[0] + mx[1] + l, mx[1] + mx[2] + 2 * l);
}

Compilation message

dreaming.cpp: In function 'void getmax(int)':
dreaming.cpp:31:10: warning: 'mxn2' may be used uninitialized in this function [-Wmaybe-uninitialized]
   31 |     calcd(mxn2, mxn2, 0, d2);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
dreaming.cpp:24:10: warning: 'mxn' may be used uninitialized in this function [-Wmaybe-uninitialized]
   24 |     calcd(mxn, mxn, 0, d);
      |     ~~~~~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 21192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 21192 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 34 ms 5548 KB Output is correct
2 Correct 36 ms 5624 KB Output is correct
3 Correct 35 ms 5584 KB Output is correct
4 Correct 46 ms 5564 KB Output is correct
5 Correct 44 ms 5584 KB Output is correct
6 Correct 33 ms 6156 KB Output is correct
7 Correct 36 ms 5876 KB Output is correct
8 Correct 38 ms 5492 KB Output is correct
9 Correct 32 ms 5420 KB Output is correct
10 Correct 45 ms 5708 KB Output is correct
11 Correct 1 ms 304 KB Output is correct
12 Correct 18 ms 3280 KB Output is correct
13 Correct 21 ms 3256 KB Output is correct
14 Correct 16 ms 3272 KB Output is correct
15 Correct 15 ms 3344 KB Output is correct
16 Correct 16 ms 3248 KB Output is correct
17 Correct 16 ms 3300 KB Output is correct
18 Correct 16 ms 3324 KB Output is correct
19 Correct 23 ms 3276 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 21 ms 3280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 112 ms 21192 KB Output isn't correct
2 Halted 0 ms 0 KB -