Submission #17153

# Submission time Handle Problem Language Result Execution time Memory
17153 2015-11-07T08:33:57 Z murat Dreaming (IOI13_dreaming) C++
14 / 100
122 ms 35732 KB
#include<bits/stdc++.h>
#include "dreaming.h"

using namespace std;

#define foreach(it, x) for(type(x) it = x.begin(); it != x.end(); it++)
#define type(x) __typeof(x.begin())
#define pb push_back
#define mp make_pair
#define nd second
#define st first

const int N = 1e6 + 5;
const int inf = 1e9 + 5;

typedef pair< int , int > pii;

int n, m, x, y, z, val[N], h[N];
vector< pii > v[N];

pii dfs(int node, int root = 0) {
    pii tt = mp(0, node);
    foreach(it, v[node])
        if(it->st != root) {
            pii temp = dfs(it->st, node);
            temp.st += it->nd;
            tt = max(tt, temp);
        }
    return tt;
}

void dfs2(int node, int root = 0, int dist = 0) {
    val[node] = max(val[node], dist);
    foreach(it, v[node])
        if(it->st != root)
            dfs2(it->st, node, dist + it->nd);
}

int take(int node, int root = 0) {
    int nnn = node;
    h[node] = 1;
    foreach(it, v[node])
        if(it->st != root) {
            int ttt = take(it->st, node);
            if(val[ttt] < val[nnn])
                nnn = ttt;
        }
    return nnn;
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {

    n = N;
    val[n] = inf * 2;

    for(int i = 0; i < M; i++) {
        int x = A[i], y = B[i], z = T[i];
        v[x].pb(mp(y, z));
        v[y].pb(mp(x, z));
    }

    vector< pii > gg;

    for(int i = 0; i < N; i++) {
        if(!h[i]) {
            int x = dfs(i).nd, y = dfs(x).nd;
            dfs2(x); dfs2(y);
            int nnn = take(i);
            gg.pb(mp(val[nnn], nnn));
        }
    }

    sort(gg.begin(), gg.end(), greater< pii >());

    for(int i = 1; i < gg.size(); i++) {
        v[gg[i].nd].pb(mp(gg[0].nd, L));
        v[gg[0].nd].pb(mp(gg[i].nd, L));
    }


    int x = dfs(0).nd, ans = dfs(x).st;

    return ans;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:75:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < gg.size(); i++) {
                    ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 95 ms 35720 KB Output is correct
2 Correct 98 ms 35732 KB Output is correct
3 Correct 80 ms 31456 KB Output is correct
4 Correct 33 ms 25592 KB Output is correct
5 Correct 33 ms 24700 KB Output is correct
6 Correct 42 ms 26360 KB Output is correct
7 Correct 23 ms 23936 KB Output is correct
8 Correct 63 ms 27784 KB Output is correct
9 Correct 74 ms 29432 KB Output is correct
10 Correct 22 ms 23936 KB Output is correct
11 Correct 92 ms 31096 KB Output is correct
12 Correct 122 ms 33528 KB Output is correct
13 Correct 23 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 35720 KB Output is correct
2 Correct 98 ms 35732 KB Output is correct
3 Correct 80 ms 31456 KB Output is correct
4 Correct 33 ms 25592 KB Output is correct
5 Correct 33 ms 24700 KB Output is correct
6 Correct 42 ms 26360 KB Output is correct
7 Correct 23 ms 23936 KB Output is correct
8 Correct 63 ms 27784 KB Output is correct
9 Correct 74 ms 29432 KB Output is correct
10 Correct 22 ms 23936 KB Output is correct
11 Correct 92 ms 31096 KB Output is correct
12 Correct 122 ms 33528 KB Output is correct
13 Correct 23 ms 23928 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 23 ms 23808 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 23 ms 23808 KB Output is correct
18 Correct 22 ms 23808 KB Output is correct
19 Correct 23 ms 23808 KB Output is correct
20 Correct 23 ms 23808 KB Output is correct
21 Correct 23 ms 23800 KB Output is correct
22 Correct 22 ms 23808 KB Output is correct
23 Correct 22 ms 23876 KB Output is correct
24 Correct 21 ms 23808 KB Output is correct
25 Correct 22 ms 23808 KB Output is correct
26 Correct 22 ms 23800 KB Output is correct
27 Correct 22 ms 23808 KB Output is correct
28 Incorrect 21 ms 23800 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 35720 KB Output is correct
2 Correct 98 ms 35732 KB Output is correct
3 Correct 80 ms 31456 KB Output is correct
4 Correct 33 ms 25592 KB Output is correct
5 Correct 33 ms 24700 KB Output is correct
6 Correct 42 ms 26360 KB Output is correct
7 Correct 23 ms 23936 KB Output is correct
8 Correct 63 ms 27784 KB Output is correct
9 Correct 74 ms 29432 KB Output is correct
10 Correct 22 ms 23936 KB Output is correct
11 Correct 92 ms 31096 KB Output is correct
12 Correct 122 ms 33528 KB Output is correct
13 Correct 23 ms 23928 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 23 ms 23808 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 23 ms 23808 KB Output is correct
18 Correct 22 ms 23808 KB Output is correct
19 Correct 23 ms 23808 KB Output is correct
20 Correct 23 ms 23808 KB Output is correct
21 Correct 23 ms 23800 KB Output is correct
22 Correct 22 ms 23808 KB Output is correct
23 Correct 22 ms 23876 KB Output is correct
24 Correct 21 ms 23808 KB Output is correct
25 Correct 22 ms 23808 KB Output is correct
26 Correct 22 ms 23800 KB Output is correct
27 Correct 22 ms 23808 KB Output is correct
28 Incorrect 21 ms 23800 KB Output isn't correct
29 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 72 ms 28860 KB Output is correct
2 Correct 69 ms 28828 KB Output is correct
3 Correct 67 ms 28840 KB Output is correct
4 Correct 67 ms 28832 KB Output is correct
5 Correct 64 ms 28832 KB Output is correct
6 Correct 69 ms 29680 KB Output is correct
7 Correct 66 ms 29048 KB Output is correct
8 Correct 71 ms 28728 KB Output is correct
9 Correct 105 ms 28724 KB Output is correct
10 Correct 71 ms 29024 KB Output is correct
11 Correct 23 ms 23808 KB Output is correct
12 Correct 41 ms 29352 KB Output is correct
13 Correct 40 ms 29292 KB Output is correct
14 Correct 41 ms 29292 KB Output is correct
15 Correct 40 ms 29292 KB Output is correct
16 Correct 41 ms 29292 KB Output is correct
17 Correct 38 ms 29300 KB Output is correct
18 Correct 41 ms 29388 KB Output is correct
19 Correct 44 ms 29292 KB Output is correct
20 Correct 22 ms 23884 KB Output is correct
21 Incorrect 21 ms 23808 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 35720 KB Output is correct
2 Correct 98 ms 35732 KB Output is correct
3 Correct 80 ms 31456 KB Output is correct
4 Correct 33 ms 25592 KB Output is correct
5 Correct 33 ms 24700 KB Output is correct
6 Correct 42 ms 26360 KB Output is correct
7 Correct 23 ms 23936 KB Output is correct
8 Correct 63 ms 27784 KB Output is correct
9 Correct 74 ms 29432 KB Output is correct
10 Correct 22 ms 23936 KB Output is correct
11 Correct 92 ms 31096 KB Output is correct
12 Correct 122 ms 33528 KB Output is correct
13 Correct 23 ms 23928 KB Output is correct
14 Correct 22 ms 23936 KB Output is correct
15 Correct 22 ms 23936 KB Output is correct
16 Correct 22 ms 23936 KB Output is correct
17 Correct 22 ms 23808 KB Output is correct
18 Correct 23 ms 23996 KB Output is correct
19 Correct 23 ms 24056 KB Output is correct
20 Correct 22 ms 23928 KB Output is correct
21 Correct 35 ms 23936 KB Output is correct
22 Correct 23 ms 23936 KB Output is correct
23 Correct 23 ms 23808 KB Output is correct
24 Correct 23 ms 23808 KB Output is correct
25 Correct 22 ms 23808 KB Output is correct
26 Correct 22 ms 23808 KB Output is correct
27 Correct 23 ms 23936 KB Output is correct
28 Correct 22 ms 23808 KB Output is correct
29 Correct 23 ms 23800 KB Output is correct
30 Correct 22 ms 23780 KB Output is correct
31 Correct 24 ms 23808 KB Output is correct
32 Correct 23 ms 23808 KB Output is correct
33 Correct 23 ms 23808 KB Output is correct
34 Correct 23 ms 23808 KB Output is correct
35 Correct 23 ms 23808 KB Output is correct
36 Correct 22 ms 23808 KB Output is correct
37 Correct 22 ms 23936 KB Output is correct
38 Correct 22 ms 23808 KB Output is correct
39 Correct 39 ms 23800 KB Output is correct
40 Correct 23 ms 23800 KB Output is correct
41 Incorrect 22 ms 23808 KB Output isn't correct
42 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 95 ms 35720 KB Output is correct
2 Correct 98 ms 35732 KB Output is correct
3 Correct 80 ms 31456 KB Output is correct
4 Correct 33 ms 25592 KB Output is correct
5 Correct 33 ms 24700 KB Output is correct
6 Correct 42 ms 26360 KB Output is correct
7 Correct 23 ms 23936 KB Output is correct
8 Correct 63 ms 27784 KB Output is correct
9 Correct 74 ms 29432 KB Output is correct
10 Correct 22 ms 23936 KB Output is correct
11 Correct 92 ms 31096 KB Output is correct
12 Correct 122 ms 33528 KB Output is correct
13 Correct 23 ms 23928 KB Output is correct
14 Correct 22 ms 23808 KB Output is correct
15 Correct 23 ms 23808 KB Output is correct
16 Correct 23 ms 23808 KB Output is correct
17 Correct 23 ms 23808 KB Output is correct
18 Correct 22 ms 23808 KB Output is correct
19 Correct 23 ms 23808 KB Output is correct
20 Correct 23 ms 23808 KB Output is correct
21 Correct 23 ms 23800 KB Output is correct
22 Correct 22 ms 23808 KB Output is correct
23 Correct 22 ms 23876 KB Output is correct
24 Correct 21 ms 23808 KB Output is correct
25 Correct 22 ms 23808 KB Output is correct
26 Correct 22 ms 23800 KB Output is correct
27 Correct 22 ms 23808 KB Output is correct
28 Incorrect 21 ms 23800 KB Output isn't correct
29 Halted 0 ms 0 KB -