답안 #228399

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
228399 2020-04-30T23:26:36 Z mohamedsobhi777 꿈 (IOI13_dreaming) C++14
0 / 100
48 ms 7800 KB
#include<bits/stdc++.h>
#include "dreaming.h"

using namespace std ; 

const int N = 1e5 + 7 ; 

int n , m , L ; 
int mn ; 
int vis[N] ; 
vector<pair<int , int > > adj[N]; 

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){
    if(vis[x]++)return 0 ;
    for(auto u : adj[x]){
        if(u.first==p)continue ; 
        dfs1(u.first , x) ; 
    }
    mn = min(mn , dfs(x , x)) ; 
}

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

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

    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 ans ; 
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:50:9: warning: unused variable 's' [-Wunused-variable]
     int s = v.size() ; 
         ^
dreaming.cpp: In function 'int dfs1(int, int)':
dreaming.cpp:29:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 22 ms 5496 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 48 ms 7800 KB Output isn't correct
2 Halted 0 ms 0 KB -