답안 #17154

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17154 2015-11-07T08:44:54 Z murat 꿈 (IOI13_dreaming) C++
14 / 100
122 ms 39288 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;

static int n, m, x, y, z, val[N], h[N];
static 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;
}

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

static 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;

    for(int i = 0; i < N; i++)
        v[i].clear();

    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;

    memset(val, 0, sizeof val);

    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:79:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < gg.size(); i++) {
                    ~~^~~~~~~~~~~
dreaming.cpp: At global scope:
dreaming.cpp:18:24: warning: 'z' defined but not used [-Wunused-variable]
 static int n, m, x, y, z, val[N], h[N];
                        ^
dreaming.cpp:18:21: warning: 'y' defined but not used [-Wunused-variable]
 static int n, m, x, y, z, val[N], h[N];
                     ^
dreaming.cpp:18:18: warning: 'x' defined but not used [-Wunused-variable]
 static int n, m, x, y, z, val[N], h[N];
                  ^
dreaming.cpp:18:15: warning: 'm' defined but not used [-Wunused-variable]
 static int n, m, x, y, z, val[N], h[N];
               ^
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 39160 KB Output is correct
2 Correct 120 ms 39288 KB Output is correct
3 Correct 79 ms 35192 KB Output is correct
4 Correct 34 ms 29432 KB Output is correct
5 Correct 35 ms 28664 KB Output is correct
6 Correct 44 ms 30200 KB Output is correct
7 Correct 25 ms 27776 KB Output is correct
8 Correct 63 ms 31480 KB Output is correct
9 Correct 73 ms 33272 KB Output is correct
10 Correct 26 ms 27776 KB Output is correct
11 Correct 113 ms 34908 KB Output is correct
12 Correct 122 ms 36864 KB Output is correct
13 Correct 27 ms 27904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 39160 KB Output is correct
2 Correct 120 ms 39288 KB Output is correct
3 Correct 79 ms 35192 KB Output is correct
4 Correct 34 ms 29432 KB Output is correct
5 Correct 35 ms 28664 KB Output is correct
6 Correct 44 ms 30200 KB Output is correct
7 Correct 25 ms 27776 KB Output is correct
8 Correct 63 ms 31480 KB Output is correct
9 Correct 73 ms 33272 KB Output is correct
10 Correct 26 ms 27776 KB Output is correct
11 Correct 113 ms 34908 KB Output is correct
12 Correct 122 ms 36864 KB Output is correct
13 Correct 27 ms 27904 KB Output is correct
14 Correct 25 ms 27776 KB Output is correct
15 Correct 26 ms 27768 KB Output is correct
16 Correct 27 ms 27776 KB Output is correct
17 Correct 26 ms 27776 KB Output is correct
18 Correct 26 ms 27776 KB Output is correct
19 Correct 27 ms 27768 KB Output is correct
20 Correct 26 ms 27776 KB Output is correct
21 Correct 25 ms 27776 KB Output is correct
22 Correct 26 ms 27776 KB Output is correct
23 Correct 26 ms 27772 KB Output is correct
24 Correct 26 ms 27776 KB Output is correct
25 Correct 29 ms 27776 KB Output is correct
26 Correct 26 ms 27768 KB Output is correct
27 Correct 26 ms 27768 KB Output is correct
28 Incorrect 25 ms 27768 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 39160 KB Output is correct
2 Correct 120 ms 39288 KB Output is correct
3 Correct 79 ms 35192 KB Output is correct
4 Correct 34 ms 29432 KB Output is correct
5 Correct 35 ms 28664 KB Output is correct
6 Correct 44 ms 30200 KB Output is correct
7 Correct 25 ms 27776 KB Output is correct
8 Correct 63 ms 31480 KB Output is correct
9 Correct 73 ms 33272 KB Output is correct
10 Correct 26 ms 27776 KB Output is correct
11 Correct 113 ms 34908 KB Output is correct
12 Correct 122 ms 36864 KB Output is correct
13 Correct 27 ms 27904 KB Output is correct
14 Correct 25 ms 27776 KB Output is correct
15 Correct 26 ms 27768 KB Output is correct
16 Correct 27 ms 27776 KB Output is correct
17 Correct 26 ms 27776 KB Output is correct
18 Correct 26 ms 27776 KB Output is correct
19 Correct 27 ms 27768 KB Output is correct
20 Correct 26 ms 27776 KB Output is correct
21 Correct 25 ms 27776 KB Output is correct
22 Correct 26 ms 27776 KB Output is correct
23 Correct 26 ms 27772 KB Output is correct
24 Correct 26 ms 27776 KB Output is correct
25 Correct 29 ms 27776 KB Output is correct
26 Correct 26 ms 27768 KB Output is correct
27 Correct 26 ms 27768 KB Output is correct
28 Incorrect 25 ms 27768 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 32428 KB Output is correct
2 Correct 67 ms 32412 KB Output is correct
3 Correct 68 ms 32452 KB Output is correct
4 Correct 72 ms 32416 KB Output is correct
5 Correct 76 ms 32384 KB Output is correct
6 Correct 73 ms 33136 KB Output is correct
7 Correct 66 ms 32636 KB Output is correct
8 Correct 68 ms 32312 KB Output is correct
9 Correct 70 ms 32324 KB Output is correct
10 Correct 73 ms 32568 KB Output is correct
11 Correct 25 ms 27776 KB Output is correct
12 Correct 42 ms 32924 KB Output is correct
13 Correct 42 ms 32876 KB Output is correct
14 Correct 43 ms 32876 KB Output is correct
15 Correct 42 ms 32748 KB Output is correct
16 Correct 42 ms 32884 KB Output is correct
17 Correct 42 ms 32876 KB Output is correct
18 Correct 45 ms 32876 KB Output is correct
19 Correct 43 ms 32768 KB Output is correct
20 Correct 25 ms 27748 KB Output is correct
21 Incorrect 25 ms 27776 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 39160 KB Output is correct
2 Correct 120 ms 39288 KB Output is correct
3 Correct 79 ms 35192 KB Output is correct
4 Correct 34 ms 29432 KB Output is correct
5 Correct 35 ms 28664 KB Output is correct
6 Correct 44 ms 30200 KB Output is correct
7 Correct 25 ms 27776 KB Output is correct
8 Correct 63 ms 31480 KB Output is correct
9 Correct 73 ms 33272 KB Output is correct
10 Correct 26 ms 27776 KB Output is correct
11 Correct 113 ms 34908 KB Output is correct
12 Correct 122 ms 36864 KB Output is correct
13 Correct 27 ms 27904 KB Output is correct
14 Correct 26 ms 27768 KB Output is correct
15 Correct 27 ms 27876 KB Output is correct
16 Correct 28 ms 27904 KB Output is correct
17 Correct 26 ms 27776 KB Output is correct
18 Correct 32 ms 27896 KB Output is correct
19 Correct 27 ms 27904 KB Output is correct
20 Correct 26 ms 27776 KB Output is correct
21 Correct 26 ms 27896 KB Output is correct
22 Correct 52 ms 27896 KB Output is correct
23 Correct 25 ms 27776 KB Output is correct
24 Correct 28 ms 27776 KB Output is correct
25 Correct 26 ms 27768 KB Output is correct
26 Correct 25 ms 27776 KB Output is correct
27 Correct 26 ms 27768 KB Output is correct
28 Correct 26 ms 27776 KB Output is correct
29 Correct 25 ms 27776 KB Output is correct
30 Correct 27 ms 27768 KB Output is correct
31 Correct 26 ms 27776 KB Output is correct
32 Correct 26 ms 27788 KB Output is correct
33 Correct 27 ms 27768 KB Output is correct
34 Correct 25 ms 27776 KB Output is correct
35 Correct 26 ms 27776 KB Output is correct
36 Correct 26 ms 27776 KB Output is correct
37 Correct 26 ms 27768 KB Output is correct
38 Correct 25 ms 27776 KB Output is correct
39 Correct 27 ms 27768 KB Output is correct
40 Correct 26 ms 27768 KB Output is correct
41 Incorrect 26 ms 27776 KB Output isn't correct
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 39160 KB Output is correct
2 Correct 120 ms 39288 KB Output is correct
3 Correct 79 ms 35192 KB Output is correct
4 Correct 34 ms 29432 KB Output is correct
5 Correct 35 ms 28664 KB Output is correct
6 Correct 44 ms 30200 KB Output is correct
7 Correct 25 ms 27776 KB Output is correct
8 Correct 63 ms 31480 KB Output is correct
9 Correct 73 ms 33272 KB Output is correct
10 Correct 26 ms 27776 KB Output is correct
11 Correct 113 ms 34908 KB Output is correct
12 Correct 122 ms 36864 KB Output is correct
13 Correct 27 ms 27904 KB Output is correct
14 Correct 25 ms 27776 KB Output is correct
15 Correct 26 ms 27768 KB Output is correct
16 Correct 27 ms 27776 KB Output is correct
17 Correct 26 ms 27776 KB Output is correct
18 Correct 26 ms 27776 KB Output is correct
19 Correct 27 ms 27768 KB Output is correct
20 Correct 26 ms 27776 KB Output is correct
21 Correct 25 ms 27776 KB Output is correct
22 Correct 26 ms 27776 KB Output is correct
23 Correct 26 ms 27772 KB Output is correct
24 Correct 26 ms 27776 KB Output is correct
25 Correct 29 ms 27776 KB Output is correct
26 Correct 26 ms 27768 KB Output is correct
27 Correct 26 ms 27768 KB Output is correct
28 Incorrect 25 ms 27768 KB Output isn't correct
29 Halted 0 ms 0 KB -