Submission #967982

# Submission time Handle Problem Language Result Execution time Memory
967982 2024-04-23T06:27:53 Z Hugo1729 Dreaming (IOI13_dreaming) C++11
0 / 100
29 ms 12112 KB
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
#define f first
#define s second

vector<pair<int,int>> adj[100000];

pair<int,pair<int,int>> dp[100000];
bool marked[100000]={0};

int dfs_sizes(int v, int pV){
    dp[v]={-1,{0,0}};
    marked[v]=1;
    for(auto [w,d] : adj[v]){
        if(w!=pV){
            int sus=dfs_sizes(w,v)+d;
            if(sus>dp[v].s.f)dp[v]={w,{sus,dp[v].s.f}};
            else if(sus>dp[v].s.s)dp[v].s.s=sus;
        }
    }
    return dp[v].s.f;
}

int dfs(int v, int pV=-1, int d=0){
    // cout << "d" << v << ' ' << d << '\n';
    if(dp[v].f!=-1){
        int sus=max(dp[dp[v].f].s.s,d+dp[v].s.f-dp[dp[v].f].s.f+dp[v].s.s);
        if(max(sus,dp[dp[v].f].s.f)<max(d,dp[v].s.f))return dfs(dp[v].f,v,sus);
        else return max(d,dp[v].s.f);
    }
    return max(d,dp[v].s.f);
}


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({B[i],T[i]});
        adj[B[i]].push_back({A[i],T[i]});
    }

    vector<int> sussy;

    for(int i=0;i<N;i++){
        if(!marked[i]){
            dfs_sizes(i,i);
            sussy.push_back(-dfs(i,-1,dp[i].s.s));
            cout <<i << ' ' << sussy[sussy.size()-1] << '\n';
        }

        // cout << i << ' ' << dp[i].first << ' ' << dp[i].second << '\n';

    }

    sort(sussy.begin(),sussy.end());

    if(sussy.size()==1)return -sussy[0];
    else if(sussy.size()==2)return -sussy[0]-sussy[1]+L;

    return max(-sussy[0]-sussy[1]+L,-sussy[2]-sussy[1]+L*2);
}

Compilation message

dreaming.cpp: In function 'int dfs_sizes(int, int)':
dreaming.cpp:15:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     for(auto [w,d] : adj[v]){
      |              ^
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 7896 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 12112 KB Output isn't correct
2 Halted 0 ms 0 KB -