답안 #880586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880586 2023-11-29T17:08:40 Z Mr_Husanboy 꿈 (IOI13_dreaming) C++17
0 / 100
31 ms 11376 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const ll infl = 1e18;
template<typename T>
int len(T &a){
    return a.size();
}


int travelTime(int n, int m, int L, int a[], int b[], int t[]) {
    vector<vector<pair<int,int>>> g(n);
    for(int i = 0; i < m; i ++){
        g[a[i]].emplace_back(b[i], t[i]);
        g[b[i]].emplace_back(a[i], t[i]);
    }


    vector<ll> disa(n);
    vector<bool> vis(n);
    int mx = 0;

    auto dfs = [&](auto &dfs, int i, int p = -1)->void{
        vis[i] = 1;
        for(auto [u, w] : g[i]){
            if(u == p) continue;
            disa[u] = disa[i] + w;
            dfs(dfs, u, i);
        }
        if(disa[mx] < disa[i]) mx = i;
    };
    ll mxx = infl;

    auto dfs2 = [&](auto &dfs2, int i, int p = -1, ll d = 0)->void{
        vis[i] = 1;
        mxx = min(mxx, max(d, disa[i]));
        for(auto [u, w] : g[i]){
            if(u == p) continue;
            dfs2(dfs2, u, i, d + w);
        }
    };
    ll ans = 0;
    vector<ll> dis;
    for(int i = 0; i < n; i ++){
        if(vis[i]) continue;
        mx = i;
        mxx = infl;
        dfs(dfs, i);
        disa[mx] = 0;
        dfs(dfs, mx);
        ans = max(ans, disa[mx]);
        dfs2(dfs2, mx);
        dis.push_back(mxx);
    }
    if(len(dis) == 1){
        return max(ans, dis[0]);
    }
    if(len(dis) == 2){
        return max(ans, dis[0] + dis[2] + L);
    }
    sort(dis.begin(), dis.end());
    n = dis.size();
    ans = max({ans, dis[n - 1] + dis[n - 2] + L, dis[n - 1] + dis[n - 3] + 2 * L});
    return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 10072 KB Output is correct
2 Correct 31 ms 11376 KB Output is correct
3 Correct 21 ms 7772 KB Output is correct
4 Correct 6 ms 1884 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 2908 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 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 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 10072 KB Output is correct
2 Correct 31 ms 11376 KB Output is correct
3 Correct 21 ms 7772 KB Output is correct
4 Correct 6 ms 1884 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 2908 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 6368 KB Output is correct
2 Incorrect 15 ms 6296 KB Output isn't correct
3 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 Incorrect 1 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 10072 KB Output is correct
2 Correct 31 ms 11376 KB Output is correct
3 Correct 21 ms 7772 KB Output is correct
4 Correct 6 ms 1884 KB Output is correct
5 Correct 4 ms 1372 KB Output is correct
6 Correct 8 ms 2908 KB Output is correct
7 Incorrect 1 ms 348 KB Output isn't correct
8 Halted 0 ms 0 KB -