답안 #289064

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
289064 2020-09-02T10:17:41 Z Atill83 꿈 (IOI13_dreaming) C++14
18 / 100
123 ms 23928 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
typedef pair<int, int> pii;
typedef long long ll;
const int MAXN = (int) 3e5 + 5;
ll mes[MAXN], der[MAXN], asa[MAXN];
vector<pii> adj[MAXN];
vector<int> comps;
bool done[MAXN];
ll mn = 0;
void dfs1(int v, int par){
    for(pii u: adj[v]){
        if(u.ff != par){
            der[u.ff] = der[v] + u.ss; 
            dfs1(u.ff, v);
            asa[v] = max(asa[v], asa[u.ff] + u.ss);
        }
    }
}

int dfs(int v, int par, ll upD){
    done[v] = 1;
    mes[v] = max(upD, asa[v]);
    int mx = v;
    multiset<int> st;
    st.insert(upD);
    for(pii u: adj[v]){
        if(u.ff != par){
            st.insert(asa[u.ff] + u.ss);
        }
    }
    if(st.size() == 1){
        mn = max(mn,(ll) *st.rbegin());
    }else if(st.size() > 1){
        mn = max(mn, (ll)(*st.rbegin()) + (*next(st.rbegin())));
    }



    for(pii u: adj[v]){
        if(u.ff != par){
            st.erase(st.lower_bound(asa[u.ff] + u.ss));
            dfs(u.ff, v, (*st.rbegin()) + u.ss);
            st.insert(asa[u.ff] + u.ss);
            if(mes[u.ff] < mes[mx]) mx = u.ff;
        }
    }
    return mx;
}





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]});
    }

    for(int i = 0; i < N; i++){
        if(!done[i]){
            dfs1(i, -1);
            comps.push_back(dfs(i, -1, 0));
        }
        //cerr<<i<<": "<<mes[i]<<endl;
    }

    sort(comps.begin(), comps.end(), [](int a, int b){
        return mes[a] > mes[b];
    });

    if(comps.size() == 1){
        return max(mn, mes[comps[0]]);
    }else if(comps.size() == 2){
        return max(mn, L + mes[comps[0]] + mes[comps[1]]);
    }else{
        return max(mn,max(2*L + mes[comps[1]] + mes[comps[2]], L + mes[comps[0]] + mes[comps[1]]));
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 23928 KB Output is correct
2 Correct 97 ms 23032 KB Output is correct
3 Correct 63 ms 21884 KB Output is correct
4 Correct 16 ms 9728 KB Output is correct
5 Correct 13 ms 8576 KB Output is correct
6 Correct 24 ms 11008 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 23928 KB Output is correct
2 Correct 97 ms 23032 KB Output is correct
3 Correct 63 ms 21884 KB Output is correct
4 Correct 16 ms 9728 KB Output is correct
5 Correct 13 ms 8576 KB Output is correct
6 Correct 24 ms 11008 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 23928 KB Output is correct
2 Correct 97 ms 23032 KB Output is correct
3 Correct 63 ms 21884 KB Output is correct
4 Correct 16 ms 9728 KB Output is correct
5 Correct 13 ms 8576 KB Output is correct
6 Correct 24 ms 11008 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 12304 KB Output is correct
2 Correct 47 ms 12408 KB Output is correct
3 Correct 42 ms 12408 KB Output is correct
4 Correct 44 ms 12408 KB Output is correct
5 Correct 41 ms 12408 KB Output is correct
6 Correct 47 ms 12920 KB Output is correct
7 Correct 47 ms 12536 KB Output is correct
8 Correct 42 ms 12284 KB Output is correct
9 Correct 42 ms 12276 KB Output is correct
10 Correct 45 ms 12532 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 15 ms 9976 KB Output is correct
13 Correct 18 ms 10108 KB Output is correct
14 Correct 15 ms 9852 KB Output is correct
15 Correct 15 ms 9976 KB Output is correct
16 Correct 22 ms 9724 KB Output is correct
17 Correct 15 ms 9080 KB Output is correct
18 Correct 16 ms 10232 KB Output is correct
19 Correct 15 ms 9724 KB Output is correct
20 Correct 5 ms 7424 KB Output is correct
21 Correct 5 ms 7424 KB Output is correct
22 Correct 5 ms 7552 KB Output is correct
23 Correct 14 ms 9724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 23928 KB Output is correct
2 Correct 97 ms 23032 KB Output is correct
3 Correct 63 ms 21884 KB Output is correct
4 Correct 16 ms 9728 KB Output is correct
5 Correct 13 ms 8576 KB Output is correct
6 Correct 24 ms 11008 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 23928 KB Output is correct
2 Correct 97 ms 23032 KB Output is correct
3 Correct 63 ms 21884 KB Output is correct
4 Correct 16 ms 9728 KB Output is correct
5 Correct 13 ms 8576 KB Output is correct
6 Correct 24 ms 11008 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -