Submission #693309

# Submission time Handle Problem Language Result Execution time Memory
693309 2023-02-02T16:42:01 Z PoonYaPat Dreaming (IOI13_dreaming) C++14
18 / 100
37 ms 11604 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;

int dis_min,mmax1[100001],mmax2[100001],mnode[100001];
bool vis[100001];
vector<pii> adj[100001];
vector<int> v;

void dfs1(int x, int par, int root) {
    vis[x]=true;
    for (auto s : adj[x]) {
        if (s.first==par) continue;
        dfs1(s.first,x,root);
        int dis=mmax1[s.first]+s.second;

        if (mmax1[x]<=dis) {
            mmax2[x]=mmax1[x];
            mmax1[x]=dis;
            mnode[x]=s.first;
        } else if (mmax2[x]<dis) mmax2[x]=dis;
    }
}

void dfs2(int x, int par, int dis) {
    dis_min=min(dis_min,max(mmax1[x],dis));
    for (auto s : adj[x]) {
        if (s.first==par) continue;
        if (s.first==mnode[x]) dfs2(s.first,x,max(dis,mmax2[x])+s.second);
        else dfs2(s.first,x,max(dis,mmax1[x])+s.second);
    }
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for (int i=0; i<M; ++i) {
        adj[A[i]].push_back(pii(B[i],T[i]));
        adj[B[i]].push_back(pii(A[i],T[i]));
    }
    for (int i=0; i<N; ++i) {
        if (!vis[i]) {
            dfs1(i,-1,i);
            dis_min=mmax1[i];

            for (auto s : adj[i]) {
                if (s.first==mnode[i]) dfs2(mnode[i],i,mmax2[i]+s.second);
            }
            v.push_back(dis_min);
        }
    }

    sort(v.begin(),v.end(),greater<int>());
    if (v.size()==1) return v[0];
    else if (v.size()==2) return v[0]+v[1]+L;
    return max(v[0]+v[1]+L,v[1]+v[2]+2*L);
}
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 11604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 11604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6472 KB Output is correct
2 Correct 19 ms 6484 KB Output is correct
3 Correct 19 ms 6560 KB Output is correct
4 Correct 19 ms 6536 KB Output is correct
5 Correct 21 ms 6484 KB Output is correct
6 Correct 19 ms 7000 KB Output is correct
7 Correct 18 ms 6692 KB Output is correct
8 Correct 17 ms 6488 KB Output is correct
9 Correct 20 ms 6352 KB Output is correct
10 Correct 18 ms 6640 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 4 ms 4300 KB Output is correct
13 Correct 4 ms 4428 KB Output is correct
14 Correct 4 ms 4300 KB Output is correct
15 Correct 4 ms 4300 KB Output is correct
16 Correct 4 ms 4172 KB Output is correct
17 Correct 3 ms 3664 KB Output is correct
18 Correct 5 ms 4428 KB Output is correct
19 Correct 4 ms 4172 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 2 ms 2740 KB Output is correct
23 Correct 4 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2644 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 37 ms 11604 KB Output isn't correct
2 Halted 0 ms 0 KB -