Submission #109241

# Submission time Handle Problem Language Result Execution time Memory
109241 2019-05-05T17:48:42 Z updown1 Dreaming (IOI13_dreaming) C++17
0 / 100
82 ms 10616 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i, a, b) for(int i=a; i<b; i++)
#define ffi For(i, 0, N)
#define ffj For(j, 0, M)
#define ffa ffi ffj
#define s <<" "<<
#define c <<" : "<<
#define w cout
#define e "\n"
#define pb push_back
#define mp make_pair
#define a first
#define b second
//#define int ll
const int MAXN = 100000, INF = 1000000000;
//500,000,000 operations
int farund[MAXN], far2[MAXN], out, sm;
pair<int, int> far1[MAXN]; /// (value, child)
vector<int> vals;
bool vis[MAXN];
vector<pair<int, int> > adj[MAXN];

void go1(int at) {
    if (vis[at]) return;
    vis[at] = true;
    for (auto i: adj[at]) if (!vis[i.a]) {
        go1(i.a);
        farund[at] = max(farund[at], i.b+farund[i.a]);
    }
}
void go2(int at, int p, int d) {
    if (vis[at]) return;
    vis[at] = true;
    for (auto i: adj[at]) if (i.a != p) {
        int len = farund[i.a] + i.b;
        if (len > far1[at].a) {
            far2[at] = far1[at].a;
            far1[at] = mp(len, i.a);
        }
        else if (len > far2[at]) far2[at] = len;
    }
    if (at != p) {
        int up;
        if (far1[p].b == at) up = far2[p]+d;
        else up = far1[p].a + d;
        if (up > far1[at].a) {
            far2[at] = far1[at].a;
            far1[at] = mp(up, p);
        }
        else if (up > far2[at]) far2[at] = up;
        //w<< "up" s at c up<<e;
    }
    for (auto i: adj[at]) if (i.a != p) go2(i.a, at, i.b);
}
void go3(int at) {
    if (vis[at]) return;
    vis[at] = true;
    sm = min(sm, far1[at].a);
    for (auto i: adj[at]) go3(i.a);
}


int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ffj {
        int a = A[j], b = B[j], d = T[j];
        adj[a].emplace_back(b, d);
        adj[b].emplace_back(a, d);
    }
    ffi go1(i);
    ffi vis[i] = false;
    ffi go2(i, i, 0);
    //ffi w<< i c far1[i].a<<e;
    ffi out = max(out, far1[i].a);
    ffi vis[i] = false;
    ffi if (!vis[i]) {
        sm = INF;
        go3(i);
        vals.pb(sm);
    }
    while (vals.size() < 3) vals.pb(0);
    sort(vals.begin(), vals.end());
    reverse(vals.begin(), vals.end());
    out = max(out, max(vals[0]+vals[1]+L, vals[1]+vals[2]+2*L));
    return out;
}
# Verdict Execution time Memory Grader output
1 Correct 63 ms 10616 KB Output is correct
2 Correct 82 ms 10352 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3812 KB Output is correct
5 Correct 9 ms 3456 KB Output is correct
6 Correct 18 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 10616 KB Output is correct
2 Correct 82 ms 10352 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3812 KB Output is correct
5 Correct 9 ms 3456 KB Output is correct
6 Correct 18 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 10616 KB Output is correct
2 Correct 82 ms 10352 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3812 KB Output is correct
5 Correct 9 ms 3456 KB Output is correct
6 Correct 18 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6904 KB Output is correct
2 Correct 33 ms 7032 KB Output is correct
3 Correct 29 ms 6904 KB Output is correct
4 Correct 28 ms 7032 KB Output is correct
5 Correct 34 ms 7016 KB Output is correct
6 Correct 33 ms 7416 KB Output is correct
7 Correct 32 ms 7184 KB Output is correct
8 Correct 30 ms 6912 KB Output is correct
9 Correct 33 ms 6932 KB Output is correct
10 Correct 27 ms 7032 KB Output is correct
11 Correct 3 ms 2688 KB Output is correct
12 Correct 9 ms 4988 KB Output is correct
13 Correct 9 ms 4988 KB Output is correct
14 Correct 9 ms 4860 KB Output is correct
15 Correct 9 ms 4988 KB Output is correct
16 Correct 9 ms 4732 KB Output is correct
17 Correct 8 ms 3964 KB Output is correct
18 Correct 10 ms 4988 KB Output is correct
19 Correct 8 ms 4860 KB Output is correct
20 Incorrect 3 ms 2688 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 10616 KB Output is correct
2 Correct 82 ms 10352 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3812 KB Output is correct
5 Correct 9 ms 3456 KB Output is correct
6 Correct 18 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 10616 KB Output is correct
2 Correct 82 ms 10352 KB Output is correct
3 Correct 41 ms 8696 KB Output is correct
4 Correct 11 ms 3812 KB Output is correct
5 Correct 9 ms 3456 KB Output is correct
6 Correct 18 ms 4352 KB Output is correct
7 Incorrect 4 ms 2688 KB Output isn't correct
8 Halted 0 ms 0 KB -