Submission #415793

# Submission time Handle Problem Language Result Execution time Memory
415793 2021-06-01T14:42:35 Z Emin2004 Dreaming (IOI13_dreaming) C++14
18 / 100
63 ms 15292 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], dis1[N], dis2[N];
vector <pii> v[N];
vector <int> vis;

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

void DFS1(int node){
    used[node] = 2;
    for(pii i : v[node]){
        if(used[i.F] != 2){
            dis1[i.F] = dis1[node] + i.S;
            DFS1(i.F);
        }
    }
}

void DFS2(int node){
    used[node] = 3;
    for(pii i : v[node]){
        if(used[i.F] != 3){
            dis2[i.F] = dis2[node] + i.S;
            DFS2(i.F);
        }
    }
}

int travelTime(int n, int m, int l, int a[], int b[], int t[]) {
    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]) {
            vis.clear();
            ll mx = 0, dd = i;
            DFS(dd);
            for(int j : vis){
                if(dis[j] >= mx) {
                    mx = dis[j];
                    dd = j;
                }
                dis[j] = 0;
            }

            DFS1(dd);
            mx = 0;
            for(int j : vis){
                if(dis1[j] >= mx) {
                    mx = dis1[j];
                    dd = j;
                }
            }

            dis[dd] = 0;
            DFS2(dd);
            ll res = mx;
            for(int j : vis){
                res = min(res, max(dis1[j], dis2[j]));
            }
            results.pb(res);
        }
    }
    sort(results.begin(), results.end());
    int sz = results.size();
    ll ans = results[sz - 1];
    if(sz >= 2) ans += results[sz - 2] + l;
    if(sz >= 3) ans = max(ans, results[sz - 2] + results[sz - 3] + l + l);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15292 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 34 ms 8064 KB Output is correct
2 Correct 37 ms 8080 KB Output is correct
3 Correct 28 ms 8168 KB Output is correct
4 Correct 44 ms 8128 KB Output is correct
5 Correct 37 ms 8040 KB Output is correct
6 Correct 33 ms 8900 KB Output is correct
7 Correct 27 ms 8368 KB Output is correct
8 Correct 34 ms 7960 KB Output is correct
9 Correct 26 ms 7980 KB Output is correct
10 Correct 32 ms 8264 KB Output is correct
11 Correct 2 ms 2636 KB Output is correct
12 Correct 9 ms 5956 KB Output is correct
13 Correct 9 ms 6084 KB Output is correct
14 Correct 10 ms 5808 KB Output is correct
15 Correct 10 ms 5956 KB Output is correct
16 Correct 9 ms 5700 KB Output is correct
17 Correct 8 ms 4988 KB Output is correct
18 Correct 10 ms 6212 KB Output is correct
19 Correct 9 ms 5700 KB Output is correct
20 Correct 2 ms 2636 KB Output is correct
21 Correct 2 ms 2636 KB Output is correct
22 Correct 3 ms 2764 KB Output is correct
23 Correct 9 ms 5700 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 2628 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 15292 KB Output isn't correct
2 Halted 0 ms 0 KB -