Submission #557388

# Submission time Handle Problem Language Result Execution time Memory
557388 2022-05-05T09:03:56 Z Jarif_Rahman Dreaming (IOI13_dreaming) C++17
18 / 100
39 ms 11852 KB
#include "dreaming.h"
#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;

vector<vector<pair<int, int>>> v;
vector<bool> bl;
vector<int> dis;

void dfs1(int nd, int ss){
    bl[nd] = 1;
    for(auto [x, w]: v[nd]) if(x != ss) dfs1(x, nd);
    for(auto [x, w]: v[nd]) if(x != ss) dis[nd] = max(dis[nd], dis[x]+w);
}
int dfs2(int nd, int ss, int s = 0){
    int mx = s, smx = s;
    int rt = s;
    for(auto [x, w]: v[nd]) if(x != ss){
        rt = max(rt, dis[x]+w);
        if(dis[x]+w > mx) smx = mx, mx = dis[x]+w;
        else if(dis[x]+w > smx) smx = dis[x]+w;
    }
    for(auto [x, w]: v[nd]) if(x != ss) rt = min(rt, dfs2(x, nd, (dis[x]+w == mx?smx:mx)+w));
    return rt;
}

int travelTime(int n, int m, int L, int A[], int B[], int T[]){
    v.assign(n, {});
    bl.assign(n, 0);
    dis.assign(n, 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<int> sth;

    for(int i = 0; i < n; i++){
        if(bl[i]) continue;
        dfs1(i, -1);
        sth.pb(dfs2(i, -1));
    }

    sort(sth.rbegin(), sth.rend());

    if(sth.size() == 1) return sth[0];

    int ans = sth[0]+sth[1]+L;
    if(sth.size() > 2) ans = max(ans, sth[1]+sth[2]+2*L);

    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 11852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 11852 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 5908 KB Output is correct
2 Correct 18 ms 6000 KB Output is correct
3 Correct 19 ms 5884 KB Output is correct
4 Correct 19 ms 5972 KB Output is correct
5 Correct 18 ms 5916 KB Output is correct
6 Correct 19 ms 6592 KB Output is correct
7 Correct 18 ms 6196 KB Output is correct
8 Correct 20 ms 5848 KB Output is correct
9 Correct 17 ms 5880 KB Output is correct
10 Correct 20 ms 6120 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 4 ms 3664 KB Output is correct
13 Correct 5 ms 3664 KB Output is correct
14 Correct 4 ms 3664 KB Output is correct
15 Correct 5 ms 3664 KB Output is correct
16 Correct 4 ms 3664 KB Output is correct
17 Correct 4 ms 3664 KB Output is correct
18 Correct 5 ms 3768 KB Output is correct
19 Correct 4 ms 3664 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 5 ms 3664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 11852 KB Output isn't correct
2 Halted 0 ms 0 KB -