답안 #931265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931265 2024-02-21T13:27:13 Z Art_ogo 꿈 (IOI13_dreaming) C++17
18 / 100
51 ms 20652 KB
#include <bits/stdc++.h>
#include "dreaming.h"

#define ve vector 
#define all(x) x.begin(), x.end()
#define fi first
#define se second

using namespace std;

typedef pair<int, int> pii;

const int MAXN = 1e5+10;

ve<pii> g[MAXN];
bool vis[MAXN];
int dp[MAXN];

void calcdst(int v){
    vis[v] = 1;
    dp[v] = 0;
    for(auto to : g[v])
        if(!vis[to.fi]){
            calcdst(to.fi);
            dp[v] = max(dp[v], dp[to.fi] + to.se);
        }
}

int dfs(int v, int p, int curmx){
    ve<int> dsts = {curmx};
    for(auto& to : g[v])
        if(to.fi != p)
            dsts.push_back(dp[to.fi] + to.se);
    sort(all(dsts), greater<int>());
    int res = dsts[0];
    multiset<int, greater<int> > cdst;
    for(auto i : dsts)
        cdst.insert(i);
    
    for(auto& to : g[v])
        if(to.fi != p){
            cdst.erase(cdst.find(dp[to.fi] + to.se));
            res = min(res, dfs(to.fi, v, *cdst.begin() + to.se));
            cdst.insert(dp[to.fi] + to.se);
        }
    return res;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    for(int i = 0; i < M; i++){
        int u = A[i], v = B[i], w = T[i];
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    ve<int> v;
    for(int i = 0; i < N; i++)
        if(!vis[i]){
            calcdst(i);
            v.push_back(dfs(i, i, 0));
        }
    sort(all(v), greater<int>());
    if(v.size() == 1)
        return v[0];
    else if(v.size() == 2)
        return v[0] + v[1] + L;
    else 
        return max(v[0] + v[1] + L, v[1] + v[2] + 2*L);
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 20652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 20652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 6616 KB Output is correct
2 Correct 21 ms 6744 KB Output is correct
3 Correct 20 ms 6624 KB Output is correct
4 Correct 19 ms 6744 KB Output is correct
5 Correct 23 ms 6616 KB Output is correct
6 Correct 20 ms 6880 KB Output is correct
7 Correct 20 ms 6748 KB Output is correct
8 Correct 18 ms 6620 KB Output is correct
9 Correct 18 ms 6616 KB Output is correct
10 Correct 19 ms 6748 KB Output is correct
11 Correct 1 ms 4188 KB Output is correct
12 Correct 9 ms 4900 KB Output is correct
13 Correct 7 ms 4824 KB Output is correct
14 Correct 7 ms 4824 KB Output is correct
15 Correct 7 ms 4824 KB Output is correct
16 Correct 7 ms 4824 KB Output is correct
17 Correct 7 ms 4856 KB Output is correct
18 Correct 9 ms 4824 KB Output is correct
19 Correct 7 ms 4824 KB Output is correct
20 Correct 2 ms 4192 KB Output is correct
21 Correct 1 ms 4188 KB Output is correct
22 Correct 2 ms 4188 KB Output is correct
23 Correct 10 ms 4824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4188 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 51 ms 20652 KB Output isn't correct
2 Halted 0 ms 0 KB -