Submission #880585

# Submission time Handle Problem Language Result Execution time Memory
880585 2023-11-29T17:06:50 Z Mr_Husanboy Dreaming (IOI13_dreaming) C++17
0 / 100
32 ms 10040 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 dis[0];
    }
    if(len(dis) == 2){
        return 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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 10040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 10040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 16 ms 6112 KB Output is correct
2 Incorrect 16 ms 6360 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 32 ms 10040 KB Output isn't correct
2 Halted 0 ms 0 KB -