Submission #289055

# Submission time Handle Problem Language Result Execution time Memory
289055 2020-09-02T10:11:26 Z Atill83 Dreaming (IOI13_dreaming) C++14
18 / 100
111 ms 24184 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];

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);
        }
    }
    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 mes[comps[0]];
    }else if(comps.size() == 2){
        return L + mes[comps[0]] + mes[comps[1]];
    }else{
        return max(2*L + mes[comps[1]] + mes[comps[2]], L + mes[comps[0]] + mes[comps[1]]);
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 24184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 24184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 24184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 12788 KB Output is correct
2 Correct 76 ms 12792 KB Output is correct
3 Correct 45 ms 12684 KB Output is correct
4 Correct 46 ms 12792 KB Output is correct
5 Correct 42 ms 12792 KB Output is correct
6 Correct 64 ms 13308 KB Output is correct
7 Correct 53 ms 13044 KB Output is correct
8 Correct 42 ms 12672 KB Output is correct
9 Correct 64 ms 12660 KB Output is correct
10 Correct 44 ms 12916 KB Output is correct
11 Correct 5 ms 7456 KB Output is correct
12 Correct 15 ms 9976 KB Output is correct
13 Correct 15 ms 10108 KB Output is correct
14 Correct 15 ms 9852 KB Output is correct
15 Correct 14 ms 9976 KB Output is correct
16 Correct 14 ms 9724 KB Output is correct
17 Correct 15 ms 9080 KB Output is correct
18 Correct 15 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 6 ms 7552 KB Output is correct
22 Correct 5 ms 7424 KB Output is correct
23 Correct 15 ms 9724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 24184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 111 ms 24184 KB Output isn't correct
2 Halted 0 ms 0 KB -