답안 #426925

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426925 2021-06-14T10:54:05 Z AmineWeslati 꿈 (IOI13_dreaming) C++14
47 / 100
1000 ms 16384 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int>vi; 
#define pb push_back
#define sz(v) (int)v.size()

typedef pair<int,int>pi;
#define fi first
#define se second
typedef vector<pi>vpi;
#define eb emplace_back

#define FOR(i,a,b) for(int i=a; i<b; i++)
#define ROF(i,a,b) for(int i=b-1; i>=a; i--)


void ckmax(int &x, int y){x=max(x,y);}
void ckmin(int &x, int y){x=min(x,y);}

const int MX=1e5+10;
int N,M; 
vpi adj[MX];
vi vis(MX,0);

vi dist(MX);
pi par[MX]; 
void dfs(int u){
    vis[u]=1;
    for(auto it: adj[u]){
        int v=it.fi,w=it.se;
        if(dist[v]==-1){
            dist[v]=dist[u]+w;
            par[v]={u,w};
            dfs(v);
        }
    } 
}

int U,V,diam;

void solve(int u){
    FOR(i,0,N) dist[i]=-1; dist[u]=0; 
    dfs(u);
    int v=u; 
    FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i; 

    u=v; 

    FOR(i,0,N) dist[i]=-1; dist[u]=0;
    dfs(u);
    v=u; 
    FOR(i,0,N) if(dist[i]!=-1 && dist[i]>dist[v]) v=i; 

    diam=dist[v];
    tie(U,V)={u,v};
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    ::N=N; ::M=M; 
    FOR(i,0,M){
        int u=A[i],v=B[i],w=T[i];
        adj[u].eb(v,w);
        adj[v].eb(u,w);
    }

    int ans=0;
    vi vec; 
    FOR(i,0,N) if(!vis[i]){
        solve(i);
        ckmax(ans,diam);
        
        int cur=0,mn=diam;
        //cout << U << " " << V << endl;
        while(U!=V){
            cur+=par[V].se; 
            V=par[V].fi;

            ckmin(mn,max(diam-cur,cur));
        }
        vec.pb(mn);
    }
    assert(sz(vec)==2);
    ckmax(ans,vec[0]+vec[1]+L);
    return ans; 
}

/*
12
8
2
0 8 2 5 5 1 1 10
8 2 7 11 1 3 9 6
4 2 4 3 7 1 5 3

*/

/*
12
10
5
0 0 0 1 1 3 7 7 5 5 
1 2 3 4 5 6 8 9 10 11
2 3 1 4 1 6 5 5 5 5 

*/

Compilation message

dreaming.cpp: In function 'void solve(int)':
dreaming.cpp:16:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:45:5: note: in expansion of macro 'FOR'
   45 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:45:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
dreaming.cpp:16:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   16 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:52:5: note: in expansion of macro 'FOR'
   52 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:52:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   52 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 13764 KB Output is correct
2 Correct 60 ms 13708 KB Output is correct
3 Correct 41 ms 10180 KB Output is correct
4 Correct 8 ms 4904 KB Output is correct
5 Correct 8 ms 4172 KB Output is correct
6 Correct 14 ms 5620 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 26 ms 6940 KB Output is correct
9 Correct 34 ms 8428 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 58 ms 9908 KB Output is correct
12 Correct 70 ms 11716 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 2 ms 3452 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3452 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3444 KB Output is correct
22 Correct 3 ms 3456 KB Output is correct
23 Correct 3 ms 3456 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 13764 KB Output is correct
2 Correct 60 ms 13708 KB Output is correct
3 Correct 41 ms 10180 KB Output is correct
4 Correct 8 ms 4904 KB Output is correct
5 Correct 8 ms 4172 KB Output is correct
6 Correct 14 ms 5620 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 26 ms 6940 KB Output is correct
9 Correct 34 ms 8428 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 58 ms 9908 KB Output is correct
12 Correct 70 ms 11716 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 2 ms 3452 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 2 ms 3404 KB Output is correct
28 Correct 2 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3452 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 2 ms 3444 KB Output is correct
35 Correct 3 ms 3456 KB Output is correct
36 Correct 3 ms 3456 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 3 ms 3456 KB Output is correct
39 Correct 62 ms 15048 KB Output is correct
40 Correct 55 ms 14912 KB Output is correct
41 Correct 41 ms 11144 KB Output is correct
42 Correct 9 ms 5072 KB Output is correct
43 Correct 2 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 3 ms 3404 KB Output is correct
47 Correct 3 ms 3404 KB Output is correct
48 Correct 3 ms 3452 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 3 ms 3456 KB Output is correct
51 Correct 3 ms 3404 KB Output is correct
52 Correct 3 ms 3404 KB Output is correct
53 Correct 3 ms 3452 KB Output is correct
54 Correct 2 ms 3404 KB Output is correct
55 Correct 2 ms 3404 KB Output is correct
56 Correct 2 ms 3404 KB Output is correct
57 Correct 77 ms 10720 KB Output is correct
58 Correct 99 ms 10672 KB Output is correct
59 Correct 71 ms 10556 KB Output is correct
60 Correct 87 ms 10692 KB Output is correct
61 Correct 70 ms 10676 KB Output is correct
62 Correct 76 ms 10744 KB Output is correct
63 Correct 71 ms 10408 KB Output is correct
64 Correct 68 ms 10284 KB Output is correct
65 Correct 73 ms 10600 KB Output is correct
66 Correct 77 ms 10620 KB Output is correct
67 Correct 72 ms 10564 KB Output is correct
68 Correct 77 ms 10564 KB Output is correct
69 Correct 76 ms 10860 KB Output is correct
70 Correct 85 ms 10872 KB Output is correct
71 Correct 2 ms 3404 KB Output is correct
72 Correct 4 ms 3660 KB Output is correct
73 Correct 4 ms 3660 KB Output is correct
74 Correct 4 ms 3632 KB Output is correct
75 Correct 4 ms 3660 KB Output is correct
76 Correct 4 ms 3660 KB Output is correct
77 Correct 4 ms 3660 KB Output is correct
78 Correct 4 ms 3660 KB Output is correct
79 Correct 4 ms 3660 KB Output is correct
80 Correct 86 ms 10564 KB Output is correct
81 Correct 91 ms 10596 KB Output is correct
82 Correct 79 ms 10664 KB Output is correct
83 Correct 79 ms 10748 KB Output is correct
84 Correct 4 ms 3588 KB Output is correct
85 Correct 3 ms 3592 KB Output is correct
86 Correct 5 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 4 ms 3596 KB Output is correct
89 Correct 3 ms 3532 KB Output is correct
90 Correct 4 ms 3596 KB Output is correct
91 Correct 4 ms 3660 KB Output is correct
92 Correct 4 ms 3652 KB Output is correct
93 Correct 5 ms 3532 KB Output is correct
94 Correct 3 ms 3404 KB Output is correct
95 Correct 3 ms 3404 KB Output is correct
96 Correct 2 ms 3404 KB Output is correct
97 Correct 3 ms 3404 KB Output is correct
98 Correct 3 ms 3404 KB Output is correct
99 Correct 3 ms 3448 KB Output is correct
100 Correct 3 ms 3460 KB Output is correct
101 Correct 3 ms 3404 KB Output is correct
102 Correct 3 ms 3404 KB Output is correct
103 Correct 3 ms 3404 KB Output is correct
104 Correct 8 ms 4300 KB Output is correct
105 Correct 14 ms 5956 KB Output is correct
106 Correct 3 ms 3520 KB Output is correct
107 Correct 26 ms 7484 KB Output is correct
108 Correct 32 ms 9148 KB Output is correct
109 Correct 4 ms 3452 KB Output is correct
110 Correct 49 ms 11084 KB Output is correct
111 Correct 66 ms 12940 KB Output is correct
112 Correct 3 ms 3532 KB Output is correct
113 Correct 112 ms 16384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1093 ms 6700 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 2 ms 3452 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 3 ms 3404 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 2 ms 3404 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 2 ms 3404 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 2 ms 3404 KB Output is correct
15 Correct 2 ms 3404 KB Output is correct
16 Correct 2 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3452 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3444 KB Output is correct
22 Correct 3 ms 3456 KB Output is correct
23 Correct 3 ms 3456 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3456 KB Output is correct
26 Runtime error 7 ms 6860 KB Execution killed with signal 6
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 55 ms 13764 KB Output is correct
2 Correct 60 ms 13708 KB Output is correct
3 Correct 41 ms 10180 KB Output is correct
4 Correct 8 ms 4904 KB Output is correct
5 Correct 8 ms 4172 KB Output is correct
6 Correct 14 ms 5620 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 26 ms 6940 KB Output is correct
9 Correct 34 ms 8428 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 58 ms 9908 KB Output is correct
12 Correct 70 ms 11716 KB Output is correct
13 Correct 3 ms 3532 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 2 ms 3452 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 2 ms 3404 KB Output is correct
20 Correct 3 ms 3404 KB Output is correct
21 Correct 2 ms 3404 KB Output is correct
22 Correct 2 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 2 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 2 ms 3404 KB Output is correct
28 Correct 2 ms 3404 KB Output is correct
29 Correct 2 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3452 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3404 KB Output is correct
34 Correct 2 ms 3444 KB Output is correct
35 Correct 3 ms 3456 KB Output is correct
36 Correct 3 ms 3456 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 3 ms 3456 KB Output is correct
39 Correct 62 ms 15048 KB Output is correct
40 Correct 55 ms 14912 KB Output is correct
41 Correct 41 ms 11144 KB Output is correct
42 Correct 9 ms 5072 KB Output is correct
43 Correct 2 ms 3404 KB Output is correct
44 Correct 2 ms 3404 KB Output is correct
45 Correct 2 ms 3404 KB Output is correct
46 Correct 3 ms 3404 KB Output is correct
47 Correct 3 ms 3404 KB Output is correct
48 Correct 3 ms 3452 KB Output is correct
49 Correct 2 ms 3404 KB Output is correct
50 Correct 3 ms 3456 KB Output is correct
51 Correct 3 ms 3404 KB Output is correct
52 Correct 3 ms 3404 KB Output is correct
53 Correct 3 ms 3452 KB Output is correct
54 Correct 2 ms 3404 KB Output is correct
55 Correct 2 ms 3404 KB Output is correct
56 Correct 2 ms 3404 KB Output is correct
57 Correct 77 ms 10720 KB Output is correct
58 Correct 99 ms 10672 KB Output is correct
59 Correct 71 ms 10556 KB Output is correct
60 Correct 87 ms 10692 KB Output is correct
61 Correct 70 ms 10676 KB Output is correct
62 Correct 76 ms 10744 KB Output is correct
63 Correct 71 ms 10408 KB Output is correct
64 Correct 68 ms 10284 KB Output is correct
65 Correct 73 ms 10600 KB Output is correct
66 Correct 77 ms 10620 KB Output is correct
67 Correct 72 ms 10564 KB Output is correct
68 Correct 77 ms 10564 KB Output is correct
69 Correct 76 ms 10860 KB Output is correct
70 Correct 85 ms 10872 KB Output is correct
71 Correct 2 ms 3404 KB Output is correct
72 Correct 4 ms 3660 KB Output is correct
73 Correct 4 ms 3660 KB Output is correct
74 Correct 4 ms 3632 KB Output is correct
75 Correct 4 ms 3660 KB Output is correct
76 Correct 4 ms 3660 KB Output is correct
77 Correct 4 ms 3660 KB Output is correct
78 Correct 4 ms 3660 KB Output is correct
79 Correct 4 ms 3660 KB Output is correct
80 Correct 86 ms 10564 KB Output is correct
81 Correct 91 ms 10596 KB Output is correct
82 Correct 79 ms 10664 KB Output is correct
83 Correct 79 ms 10748 KB Output is correct
84 Correct 4 ms 3588 KB Output is correct
85 Correct 3 ms 3592 KB Output is correct
86 Correct 5 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 4 ms 3596 KB Output is correct
89 Correct 3 ms 3532 KB Output is correct
90 Correct 4 ms 3596 KB Output is correct
91 Correct 4 ms 3660 KB Output is correct
92 Correct 4 ms 3652 KB Output is correct
93 Correct 5 ms 3532 KB Output is correct
94 Correct 3 ms 3404 KB Output is correct
95 Correct 3 ms 3404 KB Output is correct
96 Correct 2 ms 3404 KB Output is correct
97 Correct 3 ms 3404 KB Output is correct
98 Correct 3 ms 3404 KB Output is correct
99 Correct 3 ms 3448 KB Output is correct
100 Correct 3 ms 3460 KB Output is correct
101 Correct 3 ms 3404 KB Output is correct
102 Correct 3 ms 3404 KB Output is correct
103 Correct 3 ms 3404 KB Output is correct
104 Correct 8 ms 4300 KB Output is correct
105 Correct 14 ms 5956 KB Output is correct
106 Correct 3 ms 3520 KB Output is correct
107 Correct 26 ms 7484 KB Output is correct
108 Correct 32 ms 9148 KB Output is correct
109 Correct 4 ms 3452 KB Output is correct
110 Correct 49 ms 11084 KB Output is correct
111 Correct 66 ms 12940 KB Output is correct
112 Correct 3 ms 3532 KB Output is correct
113 Correct 112 ms 16384 KB Output is correct
114 Execution timed out 1093 ms 6700 KB Time limit exceeded
115 Halted 0 ms 0 KB -