Submission #415770

# Submission time Handle Problem Language Result Execution time Memory
415770 2021-06-01T13:36:11 Z Emin2004 Dreaming (IOI13_dreaming) C++14
0 / 100
86 ms 15932 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define pii pair<int, ll>
#define F first
#define S second

const int N = 100005;

int used[N];
ll dis[N][2];
vector <pii> v[N];
vector <int> vis;

void DFS(int node, int r){
    used[node] = 1;
    vis.pb(node);
    for(pii i : v[node]){
        if(!used[i.F]){
            used[i.F] = 1;
            dis[i.F][r] = dis[node][r] + i.S;
            DFS(i.F, r);
        }
    }
}

int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
   // return n;
    if(n == 1) return 0;
    for(int i = 0; i < m; i++){
        v[a[i]].pb({b[i], t[i]});
        v[b[i]].pb({a[i], t[i]});
    }
    vector<ll> results;
    for(int i = 0; i < n; i++){
        if(!used[i]) {
            ll mx = 0, dd = i;
            dis[dd][0] = 0;
            DFS(dd, 0);
            for(int j : vis){
                used[j] = 0;
                if(dis[j][0] >= mx) {
                    mx = dis[j][0];
                    dd = j;
                }
                dis[j][0] = 0;
            }

            vis.clear();
            dis[dd][0] = 0;
            DFS(dd, 0);
            mx = 0;
            for(int j : vis){
                used[j] = 0;
                if(dis[j][0] >= mx) {
                    mx = dis[j][0];
                    dd = j;
                }
            }

            vis.clear();
            dis[dd][1] = 0;
            DFS(dd, 1);
            for(int j : vis){
                mx = min(mx, max(dis[j][0], dis[j][1]));
            }
            vis.clear();
            results.pb(mx);
        }
    }
    sort(results.begin(), results.end());
    int sz = results.size();
    ll ans = results[sz - 1];
    if(sz >= 2) ans += results[sz - 2] + l;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 15932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 15932 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 7388 KB Output is correct
2 Incorrect 37 ms 7424 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2636 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 86 ms 15932 KB Output isn't correct
2 Halted 0 ms 0 KB -