Submission #434627

# Submission time Handle Problem Language Result Execution time Memory
434627 2021-06-21T13:22:54 Z Trunkty Dreaming (IOI13_dreaming) C++14
0 / 100
108 ms 25428 KB
#include "dreaming.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;

vector<vector<int>> pairs[100005];
bool check[100005];
int mini;
int dp[100005][3];
priority_queue<int> nums;

int dfs(int par, int a, int curr){
    check[a] = true;
    for(vector<int> i:pairs[a]){
        if(i[0]!=par){
            int x = dfs(a,i[0],i[1]);
            if(x>dp[a][1]){
                dp[a][2] = dp[a][1];
                dp[a][1] = x;
            }
            else if(x>dp[a][2]){
                dp[a][2] = x;
            }
        }
    }
    return dp[a][1]+curr;
}

void dfs2(int par, int a, int curr){
    if(curr>dp[a][1]){
        dp[a][2] = dp[a][1];
        dp[a][1] = curr;
    }
    else if(curr>dp[a][2]){
        dp[a][2] = curr;
    }
    for(vector<int> i:pairs[a]){
        if(i[0]!=par){
            if(dp[i[0]][1]+i[1]==dp[a][1]){
                dfs2(a,i[0],dp[a][2]+i[1]);
            }
            else{
                dfs2(a,i[0],dp[a][1]+i[1]);
            }
        }
    }
    mini = min(mini,dp[a][1]);
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i=0;i<M;i++){
        pairs[A[i]].push_back({B[i],T[i]});
        pairs[B[i]].push_back({A[i],T[i]});
    }
    for(int i=0;i<N;i++){
        if(!check[i]){
            mini = 1e9;
            dfs(-1,i,0);
            dfs2(-1,i,0);
            nums.push(mini);
        }
    }
    int a = nums.top();
    nums.pop();
    int b = nums.top();
    return a+b+L;
}
# Verdict Execution time Memory Grader output
1 Incorrect 108 ms 25428 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 108 ms 25428 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 39 ms 8908 KB Output is correct
2 Incorrect 39 ms 8884 KB Output isn't correct
3 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 108 ms 25428 KB Output isn't correct
2 Halted 0 ms 0 KB -