Submission #289058

# Submission time Handle Problem Language Result Execution time Memory
289058 2020-09-02T10:14:59 Z Atill83 Dreaming (IOI13_dreaming) C++14
18 / 100
109 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]);
    mn = max(mn, 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 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]]));
    }
}
# Verdict Execution time Memory Grader output
1 Correct 109 ms 23928 KB Output is correct
2 Correct 104 ms 23416 KB Output is correct
3 Correct 67 ms 22264 KB Output is correct
4 Correct 17 ms 9948 KB Output is correct
5 Correct 13 ms 8832 KB Output is correct
6 Correct 27 ms 11256 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 23928 KB Output is correct
2 Correct 104 ms 23416 KB Output is correct
3 Correct 67 ms 22264 KB Output is correct
4 Correct 17 ms 9948 KB Output is correct
5 Correct 13 ms 8832 KB Output is correct
6 Correct 27 ms 11256 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 23928 KB Output is correct
2 Correct 104 ms 23416 KB Output is correct
3 Correct 67 ms 22264 KB Output is correct
4 Correct 17 ms 9948 KB Output is correct
5 Correct 13 ms 8832 KB Output is correct
6 Correct 27 ms 11256 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 12404 KB Output is correct
2 Correct 46 ms 12620 KB Output is correct
3 Correct 44 ms 12408 KB Output is correct
4 Correct 44 ms 12408 KB Output is correct
5 Correct 42 ms 12408 KB Output is correct
6 Correct 45 ms 12920 KB Output is correct
7 Correct 47 ms 12536 KB Output is correct
8 Correct 41 ms 12280 KB Output is correct
9 Correct 41 ms 12276 KB Output is correct
10 Correct 62 ms 12532 KB Output is correct
11 Correct 5 ms 7424 KB Output is correct
12 Correct 23 ms 9976 KB Output is correct
13 Correct 14 ms 10108 KB Output is correct
14 Correct 22 ms 9852 KB Output is correct
15 Correct 14 ms 9976 KB Output is correct
16 Correct 20 ms 9724 KB Output is correct
17 Correct 14 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 6 ms 7424 KB Output is correct
22 Correct 6 ms 7424 KB Output is correct
23 Correct 16 ms 9724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 109 ms 23928 KB Output is correct
2 Correct 104 ms 23416 KB Output is correct
3 Correct 67 ms 22264 KB Output is correct
4 Correct 17 ms 9948 KB Output is correct
5 Correct 13 ms 8832 KB Output is correct
6 Correct 27 ms 11256 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 109 ms 23928 KB Output is correct
2 Correct 104 ms 23416 KB Output is correct
3 Correct 67 ms 22264 KB Output is correct
4 Correct 17 ms 9948 KB Output is correct
5 Correct 13 ms 8832 KB Output is correct
6 Correct 27 ms 11256 KB Output is correct
7 Incorrect 5 ms 7424 KB Output isn't correct
8 Halted 0 ms 0 KB -