답안 #228420

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228420 2020-05-01T01:44:03 Z mohamedsobhi777 꿈 (IOI13_dreaming) C++14
0 / 100
1000 ms 17148 KB
#include<bits/stdc++.h>
#include "dreaming.h"

using namespace std ; 

const int N = 1e5 + 7 ; 

int mn ; 
int vis[N] ; 
int mxx[N] ; 
int anss[N] ;  

vector<pair<int , int > > adj[N]; 
int node , dst ; 
int ansi , ans2;

int solve1(int x, int p){
    int ret = 0 ; 
    for(auto u : adj[x]){
        if(u.first==p)continue ; 
        int dfx = solve1(u.first , x) + u.second ; 
        ret = max(ret , dfx) ;
    }
    anss[x] = ret ; 
    return mxx[x] = ret ; 
}

void dfs(int x , int p , int h){
    for(auto u : adj[x]){
        if(u.first==p)continue ; 
        dfs(u.first , x , h + u.second) ; 
    }
    /*if( h > dst){
        node = x ; 
        dst = h ; 
        ans2 = max(ans2 , h) ; 
    }*/
    ans2 = max(ans2 , h) ;
}

int dfs1(int x, int p , int dp = 0 ){

    vis[x] ++ ; 

    anss[x] = max(anss[x] , dp ) ;

    for(auto u: adj[x]){
        if(u.first == p)continue ; 
        dfs1(u.first , x , 0) ; 
    }
    ansi = min(ansi , solve1(x , x)) ; 
    ans2 = max(ans2 , solve1(x , x)) ; 
    return 0 ;
    //ansi = min(ansi , anss[x]) ; 
    for(auto u : adj[x]){
        if(u.first==p)continue ;
        int subdp = 0 ;
        for(auto j : adj[x]){
            if(j.first == p || j == u){
                continue ; 
            }
            subdp = max(subdp , mxx[j.first] + j.second) ; 
        } 
        dfs1(u.first , x , max(dp , subdp) + u.second) ; 
    }
}

int pre[N] , suf[N] ; 

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i  =0 ; i< M ;i++){
        adj[A[i] +1 ].push_back({B[i]+1 , T[i]}) ;
        adj[B[i]+1].push_back({A[i]+1 , T[i]}) ;
    }
    vector<int> v; 
    multiset<int> mul ; 
    //for(int i = 1 ;i <=N ; i++)ans2 = max(ans2 , solve1(i , i) )  ; 
    for(int i = 1; i <= N && vis[i] == 0  ; i++){
        ansi = 2e9 ; 
       // if(vis[i])continue ; 
        /*dfs(i , i , 0) ; 
        dst = 0 ; 
        dfs(node , node , 0) ; 
        ans2 = max(ans2 , dst) ; */
        //solve1(i , i ) ; 
        dfs1(i , i) ;
        v.push_back(ansi) ; 
        mul.insert(ansi) ;
    }
    if(v.size() == 1)return ans2 ; 
    else if(v.size() ==2 )return max(v[0] + v[1]  + L , ans2) ; 

    int s = v.size() ; 
    int ans = 2e9 ; 

    for(auto u : v){
        mul.erase(mul.find(u)) ; 
        int mx1 = -1 , mx2 = -1 ; 
        auto e = mul.end() ;
        e-- ; mx1 = *e ; 
        e-- ; mx2 = *e ;
        int now = max(u + mx1 + L , mx1 + mx2 + L + L ) ; 
        ans = min(ans , now ) ;
        mul.insert(u) ; 
    }   
    return max(ans , ans2) ; 
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:93:9: warning: unused variable 's' [-Wunused-variable]
     int s = v.size() ; 
         ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 17148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 17148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 17148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 23 ms 6016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 17148 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1092 ms 17148 KB Time limit exceeded
2 Halted 0 ms 0 KB -