답안 #228407

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228407 2020-05-01T00:40:28 Z mohamedsobhi777 꿈 (IOI13_dreaming) C++14
0 / 100
65 ms 13304 KB
#include<bits/stdc++.h>
#include "dreaming.h"

using namespace std ; 

const int N = 1e5 + 7 ; 

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

vector<pair<int , int > > adj[N]; 
int far , dst ; 
int ansi ;
int anss[N] ;  

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 ; 
        anss[x] = max(anss[x] , ret + dfx ); 
        ret = max(ret , dfx) ;
    }
    anss[x] = ret ; 
    return mxx[x] = ret ; 
}

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

int dfs1(int x, int p , int dp = 0 ){
    vis[x] ++ ; 

    anss[x] = max(anss[x] , dp ) ;
    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 = 2; i <= N ; i++){
        mn = 2e9 ; 
        ansi = 2e9 ; 
        if(vis[i])continue ;    
        solve1(i , i ) ; 
        dfs1(i , i) ;
        v.push_back(ansi) ; 
        mul.insert(ansi) ;
    }
    if(v.size() == 1)return dst ; 
    else if(v.size() ==2 )return max(v[0] + v[1]  + L , dst) ; 

    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 , dst) ; 
}

Compilation message

dreaming.cpp: In function 'int dfs1(int, int, int)':
dreaming.cpp:55:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:78:9: warning: unused variable 's' [-Wunused-variable]
     int s = v.size() ; 
         ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 13304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 13304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 13304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 9332 KB Output is correct
2 Correct 55 ms 9564 KB Output is correct
3 Correct 53 ms 9588 KB Output is correct
4 Correct 55 ms 9588 KB Output is correct
5 Correct 65 ms 9588 KB Output is correct
6 Correct 57 ms 10228 KB Output is correct
7 Correct 58 ms 9852 KB Output is correct
8 Correct 52 ms 9460 KB Output is correct
9 Correct 53 ms 9332 KB Output is correct
10 Correct 61 ms 9716 KB Output is correct
11 Correct 6 ms 2688 KB Output is correct
12 Correct 41 ms 8944 KB Output is correct
13 Correct 42 ms 8952 KB Output is correct
14 Correct 40 ms 8952 KB Output is correct
15 Correct 39 ms 8952 KB Output is correct
16 Correct 39 ms 8952 KB Output is correct
17 Correct 46 ms 8952 KB Output is correct
18 Correct 42 ms 8952 KB Output is correct
19 Correct 43 ms 8952 KB Output is correct
20 Incorrect 6 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 13304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 13304 KB Output isn't correct
2 Halted 0 ms 0 KB -