답안 #17156

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
17156 2015-11-07T08:50:46 Z murat 꿈 (IOI13_dreaming) C++
14 / 100
118 ms 42744 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;
    gg.clear();

    memset(val, 0, sizeof val);
    memset(h, 0, sizeof h);

    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:81: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 107 ms 42616 KB Output is correct
2 Correct 118 ms 42744 KB Output is correct
3 Correct 84 ms 38952 KB Output is correct
4 Correct 37 ms 33272 KB Output is correct
5 Correct 38 ms 32504 KB Output is correct
6 Correct 49 ms 34224 KB Output is correct
7 Correct 29 ms 31736 KB Output is correct
8 Correct 63 ms 35264 KB Output is correct
9 Correct 80 ms 36996 KB Output is correct
10 Correct 28 ms 31744 KB Output is correct
11 Correct 99 ms 38364 KB Output is correct
12 Correct 112 ms 40444 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 42616 KB Output is correct
2 Correct 118 ms 42744 KB Output is correct
3 Correct 84 ms 38952 KB Output is correct
4 Correct 37 ms 33272 KB Output is correct
5 Correct 38 ms 32504 KB Output is correct
6 Correct 49 ms 34224 KB Output is correct
7 Correct 29 ms 31736 KB Output is correct
8 Correct 63 ms 35264 KB Output is correct
9 Correct 80 ms 36996 KB Output is correct
10 Correct 28 ms 31744 KB Output is correct
11 Correct 99 ms 38364 KB Output is correct
12 Correct 112 ms 40444 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
14 Correct 29 ms 31616 KB Output is correct
15 Correct 28 ms 31744 KB Output is correct
16 Correct 28 ms 31616 KB Output is correct
17 Correct 29 ms 31616 KB Output is correct
18 Correct 27 ms 31608 KB Output is correct
19 Correct 28 ms 31608 KB Output is correct
20 Correct 28 ms 31744 KB Output is correct
21 Correct 29 ms 31612 KB Output is correct
22 Correct 29 ms 31612 KB Output is correct
23 Correct 28 ms 31616 KB Output is correct
24 Correct 29 ms 31792 KB Output is correct
25 Correct 28 ms 31580 KB Output is correct
26 Correct 28 ms 31616 KB Output is correct
27 Correct 28 ms 31708 KB Output is correct
28 Incorrect 27 ms 31616 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 42616 KB Output is correct
2 Correct 118 ms 42744 KB Output is correct
3 Correct 84 ms 38952 KB Output is correct
4 Correct 37 ms 33272 KB Output is correct
5 Correct 38 ms 32504 KB Output is correct
6 Correct 49 ms 34224 KB Output is correct
7 Correct 29 ms 31736 KB Output is correct
8 Correct 63 ms 35264 KB Output is correct
9 Correct 80 ms 36996 KB Output is correct
10 Correct 28 ms 31744 KB Output is correct
11 Correct 99 ms 38364 KB Output is correct
12 Correct 112 ms 40444 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
14 Correct 29 ms 31616 KB Output is correct
15 Correct 28 ms 31744 KB Output is correct
16 Correct 28 ms 31616 KB Output is correct
17 Correct 29 ms 31616 KB Output is correct
18 Correct 27 ms 31608 KB Output is correct
19 Correct 28 ms 31608 KB Output is correct
20 Correct 28 ms 31744 KB Output is correct
21 Correct 29 ms 31612 KB Output is correct
22 Correct 29 ms 31612 KB Output is correct
23 Correct 28 ms 31616 KB Output is correct
24 Correct 29 ms 31792 KB Output is correct
25 Correct 28 ms 31580 KB Output is correct
26 Correct 28 ms 31616 KB Output is correct
27 Correct 28 ms 31708 KB Output is correct
28 Incorrect 27 ms 31616 KB Output isn't correct
29 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 70 ms 35868 KB Output is correct
2 Correct 67 ms 35952 KB Output is correct
3 Correct 75 ms 35880 KB Output is correct
4 Correct 77 ms 35996 KB Output is correct
5 Correct 68 ms 35880 KB Output is correct
6 Correct 80 ms 36716 KB Output is correct
7 Correct 70 ms 36092 KB Output is correct
8 Correct 71 ms 35896 KB Output is correct
9 Correct 65 ms 35848 KB Output is correct
10 Correct 81 ms 36064 KB Output is correct
11 Correct 27 ms 31736 KB Output is correct
12 Correct 46 ms 36332 KB Output is correct
13 Correct 46 ms 36332 KB Output is correct
14 Correct 48 ms 36332 KB Output is correct
15 Correct 47 ms 36304 KB Output is correct
16 Correct 45 ms 36336 KB Output is correct
17 Correct 46 ms 36340 KB Output is correct
18 Correct 46 ms 36340 KB Output is correct
19 Correct 47 ms 36332 KB Output is correct
20 Correct 28 ms 31660 KB Output is correct
21 Incorrect 29 ms 31608 KB Output isn't correct
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 42616 KB Output is correct
2 Correct 118 ms 42744 KB Output is correct
3 Correct 84 ms 38952 KB Output is correct
4 Correct 37 ms 33272 KB Output is correct
5 Correct 38 ms 32504 KB Output is correct
6 Correct 49 ms 34224 KB Output is correct
7 Correct 29 ms 31736 KB Output is correct
8 Correct 63 ms 35264 KB Output is correct
9 Correct 80 ms 36996 KB Output is correct
10 Correct 28 ms 31744 KB Output is correct
11 Correct 99 ms 38364 KB Output is correct
12 Correct 112 ms 40444 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
14 Correct 29 ms 31736 KB Output is correct
15 Correct 29 ms 31744 KB Output is correct
16 Correct 30 ms 31744 KB Output is correct
17 Correct 28 ms 31744 KB Output is correct
18 Correct 29 ms 31736 KB Output is correct
19 Correct 29 ms 31864 KB Output is correct
20 Correct 28 ms 31744 KB Output is correct
21 Correct 29 ms 31744 KB Output is correct
22 Correct 31 ms 31744 KB Output is correct
23 Correct 29 ms 31608 KB Output is correct
24 Correct 27 ms 31616 KB Output is correct
25 Correct 27 ms 31572 KB Output is correct
26 Correct 27 ms 31616 KB Output is correct
27 Correct 28 ms 31608 KB Output is correct
28 Correct 27 ms 31616 KB Output is correct
29 Correct 28 ms 31612 KB Output is correct
30 Correct 28 ms 31616 KB Output is correct
31 Correct 28 ms 31608 KB Output is correct
32 Correct 30 ms 31616 KB Output is correct
33 Correct 28 ms 31616 KB Output is correct
34 Correct 29 ms 31608 KB Output is correct
35 Correct 28 ms 31608 KB Output is correct
36 Correct 29 ms 31736 KB Output is correct
37 Correct 29 ms 31608 KB Output is correct
38 Correct 29 ms 31608 KB Output is correct
39 Correct 29 ms 31736 KB Output is correct
40 Correct 29 ms 31608 KB Output is correct
41 Incorrect 32 ms 31616 KB Output isn't correct
42 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 42616 KB Output is correct
2 Correct 118 ms 42744 KB Output is correct
3 Correct 84 ms 38952 KB Output is correct
4 Correct 37 ms 33272 KB Output is correct
5 Correct 38 ms 32504 KB Output is correct
6 Correct 49 ms 34224 KB Output is correct
7 Correct 29 ms 31736 KB Output is correct
8 Correct 63 ms 35264 KB Output is correct
9 Correct 80 ms 36996 KB Output is correct
10 Correct 28 ms 31744 KB Output is correct
11 Correct 99 ms 38364 KB Output is correct
12 Correct 112 ms 40444 KB Output is correct
13 Correct 28 ms 31736 KB Output is correct
14 Correct 29 ms 31616 KB Output is correct
15 Correct 28 ms 31744 KB Output is correct
16 Correct 28 ms 31616 KB Output is correct
17 Correct 29 ms 31616 KB Output is correct
18 Correct 27 ms 31608 KB Output is correct
19 Correct 28 ms 31608 KB Output is correct
20 Correct 28 ms 31744 KB Output is correct
21 Correct 29 ms 31612 KB Output is correct
22 Correct 29 ms 31612 KB Output is correct
23 Correct 28 ms 31616 KB Output is correct
24 Correct 29 ms 31792 KB Output is correct
25 Correct 28 ms 31580 KB Output is correct
26 Correct 28 ms 31616 KB Output is correct
27 Correct 28 ms 31708 KB Output is correct
28 Incorrect 27 ms 31616 KB Output isn't correct
29 Halted 0 ms 0 KB -