Submission #693316

# Submission time Handle Problem Language Result Execution time Memory
693316 2023-02-02T17:16:52 Z PoonYaPat Dreaming (IOI13_dreaming) C++14
18 / 100
43 ms 15444 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],ans;
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));

    ans=max({ans,mmax1[x]+mmax2[x],mmax1[x]+dis,mmax2[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=1; 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 max(ans,v[0]);
    else if (v.size()==2) return max(ans,v[0]+v[1]+L);
    return max({ans,v[0]+v[1]+L,v[1]+v[2]+2*L});
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 13132 KB Output is correct
2 Correct 43 ms 15444 KB Output is correct
3 Correct 26 ms 9788 KB Output is correct
4 Correct 7 ms 4180 KB Output is correct
5 Correct 5 ms 3540 KB Output is correct
6 Correct 12 ms 5460 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 13132 KB Output is correct
2 Correct 43 ms 15444 KB Output is correct
3 Correct 26 ms 9788 KB Output is correct
4 Correct 7 ms 4180 KB Output is correct
5 Correct 5 ms 3540 KB Output is correct
6 Correct 12 ms 5460 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 6468 KB Output is correct
2 Correct 17 ms 6472 KB Output is correct
3 Correct 19 ms 6624 KB Output is correct
4 Correct 18 ms 6524 KB Output is correct
5 Correct 18 ms 6536 KB Output is correct
6 Correct 26 ms 7016 KB Output is correct
7 Correct 22 ms 6616 KB Output is correct
8 Correct 17 ms 6388 KB Output is correct
9 Correct 19 ms 6400 KB Output is correct
10 Correct 17 ms 6616 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 6 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 6 ms 4172 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 4 ms 4172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Incorrect 2 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 13132 KB Output is correct
2 Correct 43 ms 15444 KB Output is correct
3 Correct 26 ms 9788 KB Output is correct
4 Correct 7 ms 4180 KB Output is correct
5 Correct 5 ms 3540 KB Output is correct
6 Correct 12 ms 5460 KB Output is correct
7 Incorrect 2 ms 2644 KB Output isn't correct
8 Halted 0 ms 0 KB -