답안 #11988

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
11988 2014-12-16T03:07:21 Z gs14004 꿈 (IOI13_dreaming) C++
59 / 100
1000 ms 14072 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <utility>
#include <queue>
#include <algorithm>
#include "dreaming.h"
using namespace std;
typedef pair<int,int> pi;
vector<pi> graph[100005];

int visited[100005];

pi get_longest(int *vis, int x){
    queue<int> q,d;
    q.push(x);
    d.push(0);
    int max = -1, maxv = -1;
    vis[x] = 1;
    while (!q.empty()) {
        int qf = q.front();
        int df = d.front();
        if(df > max){
            max = df;
            maxv = qf;
        }
        q.pop();
        d.pop();
        for (int i=0; i<graph[qf].size(); i++) {
            pi p = graph[qf][i];
            if(!vis[p.second]){
                vis[p.second] = 1;
                q.push(p.second);
                d.push(df + p.first);
            }
        }
    }
    return pi(max,maxv);
}

int ret1, len;

int dfs(int x, int d, int p, int l){
    if(x == d) return 1;
    for (int i=0; i<graph[x].size(); i++) {
        if(graph[x][i].second == p) continue;
        if(dfs(graph[x][i].second,d,x,l + graph[x][i].first)){
            ret1 = min(ret1,max(len-l,l));
            return 1;
        }
    }
    return 0;
}

int get_dia(int x){
    int tvis[100005] = {};
    int p = get_longest(tvis,x).second;
    return get_longest(visited,p).first;
}

int get_rad(int x){
    int tvis[100005] = {};
    int p = get_longest(tvis,x).second;
    pi dia = get_longest(visited,p);
    int q = dia.second;
    len = dia.first;
    ret1 = len;
    dfs(p,q,-1,0);
    return ret1;
}

int travelTime(int N, int M, int L, int* A, int* B, int* T){
    for (int i=0; i<M; i++) {
        graph[A[i]].push_back(pi(T[i],B[i]));
        graph[B[i]].push_back(pi(T[i],A[i]));
    }
    int ret = 0;
    for (int i=0; i<N; i++) {
        if(!visited[i]) ret = max(ret,get_dia(i));
    }
    memset(visited,0,sizeof(visited));
    vector<int> rad;
    for (int i=0; i<N; i++) {
        if(!visited[i]) rad.push_back(get_rad(i));
    }
    sort(rad.begin(),rad.end());
    reverse(rad.begin(),rad.end());
    if(rad.size() > 1){
        ret = max(ret,L + rad[0] + rad[1]);
    }
    if(rad.size() > 2){
        ret = max(ret,2*L + rad[1] + rad[2]);
    }
    return ret;
}
/*
int main(){
    int n,m,l,a[100005], b[100005], t[100005];
    scanf("%d %d %d",&n,&m,&l);
    for(int i=0; i<m; i++) {
        scanf("%d %d %d",&a[i],&b[i],&t[i]);
    }
    int r = travelTime(n,m,l,a,b,t);
    printf("%d",r);
}*/

Compilation message

dreaming.cpp: In function 'pi get_longest(int*, int)':
dreaming.cpp:29:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int i=0; i<graph[qf].size(); i++) {
                       ~^~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'int dfs(int, int, int, int)':
dreaming.cpp:45:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i=0; i<graph[x].size(); i++) {
                   ~^~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 92 ms 13048 KB Output is correct
3 Correct 44 ms 9720 KB Output is correct
4 Correct 12 ms 4864 KB Output is correct
5 Correct 11 ms 4224 KB Output is correct
6 Correct 19 ms 5632 KB Output is correct
7 Correct 4 ms 3456 KB Output is correct
8 Correct 32 ms 6648 KB Output is correct
9 Correct 45 ms 8056 KB Output is correct
10 Correct 4 ms 3584 KB Output is correct
11 Correct 88 ms 9392 KB Output is correct
12 Correct 81 ms 11128 KB Output is correct
13 Correct 5 ms 3584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 92 ms 13048 KB Output is correct
3 Correct 44 ms 9720 KB Output is correct
4 Correct 12 ms 4864 KB Output is correct
5 Correct 11 ms 4224 KB Output is correct
6 Correct 19 ms 5632 KB Output is correct
7 Correct 4 ms 3456 KB Output is correct
8 Correct 32 ms 6648 KB Output is correct
9 Correct 45 ms 8056 KB Output is correct
10 Correct 4 ms 3584 KB Output is correct
11 Correct 88 ms 9392 KB Output is correct
12 Correct 81 ms 11128 KB Output is correct
13 Correct 5 ms 3584 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 4 ms 3456 KB Output is correct
17 Correct 4 ms 3456 KB Output is correct
18 Correct 4 ms 3456 KB Output is correct
19 Correct 4 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 4 ms 3456 KB Output is correct
23 Correct 5 ms 3456 KB Output is correct
24 Correct 5 ms 3456 KB Output is correct
25 Correct 4 ms 3456 KB Output is correct
26 Correct 4 ms 3456 KB Output is correct
27 Correct 4 ms 3456 KB Output is correct
28 Correct 4 ms 3456 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 4 ms 3456 KB Output is correct
31 Correct 4 ms 3428 KB Output is correct
32 Correct 4 ms 3456 KB Output is correct
33 Correct 4 ms 3456 KB Output is correct
34 Correct 4 ms 3456 KB Output is correct
35 Correct 4 ms 3456 KB Output is correct
36 Correct 4 ms 3456 KB Output is correct
37 Correct 4 ms 3456 KB Output is correct
38 Correct 4 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 92 ms 13048 KB Output is correct
3 Correct 44 ms 9720 KB Output is correct
4 Correct 12 ms 4864 KB Output is correct
5 Correct 11 ms 4224 KB Output is correct
6 Correct 19 ms 5632 KB Output is correct
7 Correct 4 ms 3456 KB Output is correct
8 Correct 32 ms 6648 KB Output is correct
9 Correct 45 ms 8056 KB Output is correct
10 Correct 4 ms 3584 KB Output is correct
11 Correct 88 ms 9392 KB Output is correct
12 Correct 81 ms 11128 KB Output is correct
13 Correct 5 ms 3584 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 4 ms 3456 KB Output is correct
17 Correct 4 ms 3456 KB Output is correct
18 Correct 4 ms 3456 KB Output is correct
19 Correct 4 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 4 ms 3456 KB Output is correct
23 Correct 5 ms 3456 KB Output is correct
24 Correct 5 ms 3456 KB Output is correct
25 Correct 4 ms 3456 KB Output is correct
26 Correct 4 ms 3456 KB Output is correct
27 Correct 4 ms 3456 KB Output is correct
28 Correct 4 ms 3456 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 4 ms 3456 KB Output is correct
31 Correct 4 ms 3428 KB Output is correct
32 Correct 4 ms 3456 KB Output is correct
33 Correct 4 ms 3456 KB Output is correct
34 Correct 4 ms 3456 KB Output is correct
35 Correct 4 ms 3456 KB Output is correct
36 Correct 4 ms 3456 KB Output is correct
37 Correct 4 ms 3456 KB Output is correct
38 Correct 4 ms 3456 KB Output is correct
39 Correct 80 ms 13048 KB Output is correct
40 Correct 86 ms 13048 KB Output is correct
41 Correct 58 ms 9848 KB Output is correct
42 Correct 11 ms 4864 KB Output is correct
43 Correct 4 ms 3456 KB Output is correct
44 Correct 4 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 4 ms 3456 KB Output is correct
47 Correct 4 ms 3456 KB Output is correct
48 Correct 4 ms 3456 KB Output is correct
49 Correct 4 ms 3456 KB Output is correct
50 Correct 4 ms 3456 KB Output is correct
51 Correct 4 ms 3456 KB Output is correct
52 Correct 4 ms 3456 KB Output is correct
53 Correct 4 ms 3456 KB Output is correct
54 Correct 5 ms 3456 KB Output is correct
55 Correct 4 ms 3456 KB Output is correct
56 Correct 5 ms 3456 KB Output is correct
57 Correct 79 ms 8696 KB Output is correct
58 Correct 77 ms 8568 KB Output is correct
59 Correct 107 ms 8568 KB Output is correct
60 Correct 107 ms 8696 KB Output is correct
61 Correct 111 ms 8440 KB Output is correct
62 Correct 103 ms 8532 KB Output is correct
63 Correct 84 ms 8412 KB Output is correct
64 Correct 93 ms 8412 KB Output is correct
65 Correct 82 ms 8312 KB Output is correct
66 Correct 77 ms 8440 KB Output is correct
67 Correct 82 ms 8568 KB Output is correct
68 Correct 101 ms 8540 KB Output is correct
69 Correct 77 ms 8568 KB Output is correct
70 Correct 83 ms 8568 KB Output is correct
71 Correct 4 ms 3456 KB Output is correct
72 Correct 5 ms 3584 KB Output is correct
73 Correct 6 ms 3584 KB Output is correct
74 Correct 6 ms 3584 KB Output is correct
75 Correct 6 ms 3584 KB Output is correct
76 Correct 6 ms 3584 KB Output is correct
77 Correct 6 ms 3584 KB Output is correct
78 Correct 5 ms 3584 KB Output is correct
79 Correct 5 ms 3584 KB Output is correct
80 Correct 79 ms 8552 KB Output is correct
81 Correct 88 ms 8568 KB Output is correct
82 Correct 80 ms 8440 KB Output is correct
83 Correct 84 ms 8456 KB Output is correct
84 Correct 6 ms 3584 KB Output is correct
85 Correct 5 ms 3584 KB Output is correct
86 Correct 5 ms 3584 KB Output is correct
87 Correct 5 ms 3584 KB Output is correct
88 Correct 5 ms 3584 KB Output is correct
89 Correct 5 ms 3584 KB Output is correct
90 Correct 6 ms 3584 KB Output is correct
91 Correct 6 ms 3584 KB Output is correct
92 Correct 6 ms 3584 KB Output is correct
93 Correct 6 ms 3584 KB Output is correct
94 Correct 4 ms 3456 KB Output is correct
95 Correct 4 ms 3456 KB Output is correct
96 Correct 4 ms 3456 KB Output is correct
97 Correct 4 ms 3456 KB Output is correct
98 Correct 4 ms 3456 KB Output is correct
99 Correct 4 ms 3456 KB Output is correct
100 Correct 4 ms 3456 KB Output is correct
101 Correct 5 ms 3456 KB Output is correct
102 Correct 4 ms 3456 KB Output is correct
103 Correct 4 ms 3456 KB Output is correct
104 Correct 10 ms 4224 KB Output is correct
105 Correct 20 ms 5504 KB Output is correct
106 Correct 4 ms 3456 KB Output is correct
107 Correct 34 ms 6776 KB Output is correct
108 Correct 43 ms 8184 KB Output is correct
109 Correct 5 ms 3584 KB Output is correct
110 Correct 70 ms 9464 KB Output is correct
111 Correct 70 ms 11128 KB Output is correct
112 Correct 5 ms 3584 KB Output is correct
113 Correct 101 ms 14072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1070 ms 5760 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 92 ms 13048 KB Output is correct
3 Correct 44 ms 9720 KB Output is correct
4 Correct 12 ms 4864 KB Output is correct
5 Correct 11 ms 4224 KB Output is correct
6 Correct 19 ms 5632 KB Output is correct
7 Correct 4 ms 3456 KB Output is correct
8 Correct 32 ms 6648 KB Output is correct
9 Correct 45 ms 8056 KB Output is correct
10 Correct 4 ms 3584 KB Output is correct
11 Correct 88 ms 9392 KB Output is correct
12 Correct 81 ms 11128 KB Output is correct
13 Correct 5 ms 3584 KB Output is correct
14 Correct 11 ms 3456 KB Output is correct
15 Correct 17 ms 3584 KB Output is correct
16 Correct 25 ms 3584 KB Output is correct
17 Correct 11 ms 3456 KB Output is correct
18 Correct 17 ms 3584 KB Output is correct
19 Correct 22 ms 3584 KB Output is correct
20 Correct 10 ms 3456 KB Output is correct
21 Correct 15 ms 3584 KB Output is correct
22 Correct 22 ms 3584 KB Output is correct
23 Correct 4 ms 3428 KB Output is correct
24 Correct 4 ms 3456 KB Output is correct
25 Correct 4 ms 3456 KB Output is correct
26 Correct 4 ms 3456 KB Output is correct
27 Correct 5 ms 3456 KB Output is correct
28 Correct 8 ms 3456 KB Output is correct
29 Correct 6 ms 3456 KB Output is correct
30 Correct 4 ms 3456 KB Output is correct
31 Correct 5 ms 3456 KB Output is correct
32 Correct 5 ms 3456 KB Output is correct
33 Correct 5 ms 3456 KB Output is correct
34 Correct 5 ms 3456 KB Output is correct
35 Correct 4 ms 3456 KB Output is correct
36 Correct 4 ms 3456 KB Output is correct
37 Correct 8 ms 3456 KB Output is correct
38 Correct 4 ms 3456 KB Output is correct
39 Correct 4 ms 3456 KB Output is correct
40 Correct 4 ms 3456 KB Output is correct
41 Correct 4 ms 3456 KB Output is correct
42 Correct 7 ms 3712 KB Output is correct
43 Correct 6 ms 3712 KB Output is correct
44 Correct 59 ms 3628 KB Output is correct
45 Correct 97 ms 3576 KB Output is correct
46 Correct 5 ms 3584 KB Output is correct
47 Correct 6 ms 3584 KB Output is correct
48 Correct 71 ms 3584 KB Output is correct
49 Correct 83 ms 3564 KB Output is correct
50 Correct 6 ms 3584 KB Output is correct
51 Correct 6 ms 3584 KB Output is correct
52 Correct 102 ms 3548 KB Output is correct
53 Correct 48 ms 3584 KB Output is correct
54 Correct 6 ms 3584 KB Output is correct
55 Correct 6 ms 3584 KB Output is correct
56 Correct 46 ms 3584 KB Output is correct
57 Correct 42 ms 3576 KB Output is correct
58 Correct 78 ms 3552 KB Output is correct
59 Correct 80 ms 3704 KB Output is correct
60 Correct 6 ms 3584 KB Output is correct
61 Correct 6 ms 3584 KB Output is correct
62 Correct 14 ms 3584 KB Output is correct
63 Correct 11 ms 3584 KB Output is correct
64 Correct 6 ms 3584 KB Output is correct
65 Correct 7 ms 3584 KB Output is correct
66 Correct 79 ms 3704 KB Output is correct
67 Correct 82 ms 3576 KB Output is correct
68 Correct 112 ms 3628 KB Output is correct
69 Correct 107 ms 3448 KB Output is correct
70 Correct 21 ms 3584 KB Output is correct
71 Correct 17 ms 3584 KB Output is correct
72 Correct 78 ms 3448 KB Output is correct
73 Correct 103 ms 3556 KB Output is correct
74 Correct 45 ms 3580 KB Output is correct
75 Correct 15 ms 3584 KB Output is correct
76 Correct 46 ms 3584 KB Output is correct
77 Correct 52 ms 3576 KB Output is correct
78 Correct 69 ms 3448 KB Output is correct
79 Correct 76 ms 3580 KB Output is correct
80 Correct 5 ms 3584 KB Output is correct
81 Correct 6 ms 3584 KB Output is correct
82 Correct 6 ms 3584 KB Output is correct
83 Correct 6 ms 3584 KB Output is correct
84 Correct 6 ms 3584 KB Output is correct
85 Correct 5 ms 3584 KB Output is correct
86 Correct 6 ms 3712 KB Output is correct
87 Correct 6 ms 3584 KB Output is correct
88 Correct 7 ms 3584 KB Output is correct
89 Correct 6 ms 3584 KB Output is correct
90 Correct 5 ms 3456 KB Output is correct
91 Correct 5 ms 3456 KB Output is correct
92 Correct 4 ms 3456 KB Output is correct
93 Correct 5 ms 3456 KB Output is correct
94 Correct 4 ms 3456 KB Output is correct
95 Correct 4 ms 3456 KB Output is correct
96 Correct 4 ms 3456 KB Output is correct
97 Correct 5 ms 3456 KB Output is correct
98 Correct 4 ms 3456 KB Output is correct
99 Correct 4 ms 3456 KB Output is correct
100 Correct 4 ms 3456 KB Output is correct
101 Correct 4 ms 3584 KB Output is correct
102 Correct 4 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 13048 KB Output is correct
2 Correct 92 ms 13048 KB Output is correct
3 Correct 44 ms 9720 KB Output is correct
4 Correct 12 ms 4864 KB Output is correct
5 Correct 11 ms 4224 KB Output is correct
6 Correct 19 ms 5632 KB Output is correct
7 Correct 4 ms 3456 KB Output is correct
8 Correct 32 ms 6648 KB Output is correct
9 Correct 45 ms 8056 KB Output is correct
10 Correct 4 ms 3584 KB Output is correct
11 Correct 88 ms 9392 KB Output is correct
12 Correct 81 ms 11128 KB Output is correct
13 Correct 5 ms 3584 KB Output is correct
14 Correct 5 ms 3456 KB Output is correct
15 Correct 4 ms 3456 KB Output is correct
16 Correct 4 ms 3456 KB Output is correct
17 Correct 4 ms 3456 KB Output is correct
18 Correct 4 ms 3456 KB Output is correct
19 Correct 4 ms 3456 KB Output is correct
20 Correct 5 ms 3456 KB Output is correct
21 Correct 5 ms 3456 KB Output is correct
22 Correct 4 ms 3456 KB Output is correct
23 Correct 5 ms 3456 KB Output is correct
24 Correct 5 ms 3456 KB Output is correct
25 Correct 4 ms 3456 KB Output is correct
26 Correct 4 ms 3456 KB Output is correct
27 Correct 4 ms 3456 KB Output is correct
28 Correct 4 ms 3456 KB Output is correct
29 Correct 4 ms 3456 KB Output is correct
30 Correct 4 ms 3456 KB Output is correct
31 Correct 4 ms 3428 KB Output is correct
32 Correct 4 ms 3456 KB Output is correct
33 Correct 4 ms 3456 KB Output is correct
34 Correct 4 ms 3456 KB Output is correct
35 Correct 4 ms 3456 KB Output is correct
36 Correct 4 ms 3456 KB Output is correct
37 Correct 4 ms 3456 KB Output is correct
38 Correct 4 ms 3456 KB Output is correct
39 Correct 80 ms 13048 KB Output is correct
40 Correct 86 ms 13048 KB Output is correct
41 Correct 58 ms 9848 KB Output is correct
42 Correct 11 ms 4864 KB Output is correct
43 Correct 4 ms 3456 KB Output is correct
44 Correct 4 ms 3456 KB Output is correct
45 Correct 4 ms 3456 KB Output is correct
46 Correct 4 ms 3456 KB Output is correct
47 Correct 4 ms 3456 KB Output is correct
48 Correct 4 ms 3456 KB Output is correct
49 Correct 4 ms 3456 KB Output is correct
50 Correct 4 ms 3456 KB Output is correct
51 Correct 4 ms 3456 KB Output is correct
52 Correct 4 ms 3456 KB Output is correct
53 Correct 4 ms 3456 KB Output is correct
54 Correct 5 ms 3456 KB Output is correct
55 Correct 4 ms 3456 KB Output is correct
56 Correct 5 ms 3456 KB Output is correct
57 Correct 79 ms 8696 KB Output is correct
58 Correct 77 ms 8568 KB Output is correct
59 Correct 107 ms 8568 KB Output is correct
60 Correct 107 ms 8696 KB Output is correct
61 Correct 111 ms 8440 KB Output is correct
62 Correct 103 ms 8532 KB Output is correct
63 Correct 84 ms 8412 KB Output is correct
64 Correct 93 ms 8412 KB Output is correct
65 Correct 82 ms 8312 KB Output is correct
66 Correct 77 ms 8440 KB Output is correct
67 Correct 82 ms 8568 KB Output is correct
68 Correct 101 ms 8540 KB Output is correct
69 Correct 77 ms 8568 KB Output is correct
70 Correct 83 ms 8568 KB Output is correct
71 Correct 4 ms 3456 KB Output is correct
72 Correct 5 ms 3584 KB Output is correct
73 Correct 6 ms 3584 KB Output is correct
74 Correct 6 ms 3584 KB Output is correct
75 Correct 6 ms 3584 KB Output is correct
76 Correct 6 ms 3584 KB Output is correct
77 Correct 6 ms 3584 KB Output is correct
78 Correct 5 ms 3584 KB Output is correct
79 Correct 5 ms 3584 KB Output is correct
80 Correct 79 ms 8552 KB Output is correct
81 Correct 88 ms 8568 KB Output is correct
82 Correct 80 ms 8440 KB Output is correct
83 Correct 84 ms 8456 KB Output is correct
84 Correct 6 ms 3584 KB Output is correct
85 Correct 5 ms 3584 KB Output is correct
86 Correct 5 ms 3584 KB Output is correct
87 Correct 5 ms 3584 KB Output is correct
88 Correct 5 ms 3584 KB Output is correct
89 Correct 5 ms 3584 KB Output is correct
90 Correct 6 ms 3584 KB Output is correct
91 Correct 6 ms 3584 KB Output is correct
92 Correct 6 ms 3584 KB Output is correct
93 Correct 6 ms 3584 KB Output is correct
94 Correct 4 ms 3456 KB Output is correct
95 Correct 4 ms 3456 KB Output is correct
96 Correct 4 ms 3456 KB Output is correct
97 Correct 4 ms 3456 KB Output is correct
98 Correct 4 ms 3456 KB Output is correct
99 Correct 4 ms 3456 KB Output is correct
100 Correct 4 ms 3456 KB Output is correct
101 Correct 5 ms 3456 KB Output is correct
102 Correct 4 ms 3456 KB Output is correct
103 Correct 4 ms 3456 KB Output is correct
104 Correct 10 ms 4224 KB Output is correct
105 Correct 20 ms 5504 KB Output is correct
106 Correct 4 ms 3456 KB Output is correct
107 Correct 34 ms 6776 KB Output is correct
108 Correct 43 ms 8184 KB Output is correct
109 Correct 5 ms 3584 KB Output is correct
110 Correct 70 ms 9464 KB Output is correct
111 Correct 70 ms 11128 KB Output is correct
112 Correct 5 ms 3584 KB Output is correct
113 Correct 101 ms 14072 KB Output is correct
114 Execution timed out 1070 ms 5760 KB Time limit exceeded
115 Halted 0 ms 0 KB -