답안 #427356

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
427356 2021-06-14T14:31:01 Z AmineWeslati 꿈 (IOI13_dreaming) C++14
47 / 100
1000 ms 16420 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()
#define all(x) begin(x),end(x)

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;
        while(U!=V){
            cur+=par[V].se; 
            V=par[V].fi;

            ckmin(mn,max(diam-cur,cur));
        }
        vec.pb(mn);
    }
    sort(all(vec));
    reverse(all(vec));

    //for(auto x: vec) cout << x << endl;

    ckmax(ans,vec[0]+vec[1]+L);
    if(sz(vec)>2){
        ckmax(ans,vec[1]+vec[2]+L*2);
    }
    return ans; 
}

/*
12
8
2
0 8 4
8 2 2 
2 7 4
5 11 3
5 1 7
1 3 1
1 9 5
10 6 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:17:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   17 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:47:5: note: in expansion of macro 'FOR'
   47 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:47:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   47 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
dreaming.cpp:17:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   17 | #define FOR(i,a,b) for(int i=a; i<b; i++)
      |                    ^~~
dreaming.cpp:54:5: note: in expansion of macro 'FOR'
   54 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |     ^~~
dreaming.cpp:54:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   54 |     FOR(i,0,N) dist[i]=-1; dist[u]=0;
      |                            ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 14916 KB Output is correct
2 Correct 76 ms 14960 KB Output is correct
3 Correct 44 ms 11264 KB Output is correct
4 Correct 12 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 15 ms 5964 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 29 ms 7436 KB Output is correct
9 Correct 41 ms 9104 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 77 ms 11028 KB Output is correct
12 Correct 104 ms 12908 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 3 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 4 ms 3404 KB Output is correct
6 Correct 3 ms 3448 KB Output is correct
7 Correct 3 ms 3452 KB Output is correct
8 Correct 3 ms 3352 KB Output is correct
9 Correct 3 ms 3404 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 3 ms 3432 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 3 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3456 KB Output is correct
21 Correct 3 ms 3404 KB Output is correct
22 Correct 2 ms 3452 KB Output is correct
23 Correct 3 ms 3532 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 14916 KB Output is correct
2 Correct 76 ms 14960 KB Output is correct
3 Correct 44 ms 11264 KB Output is correct
4 Correct 12 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 15 ms 5964 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 29 ms 7436 KB Output is correct
9 Correct 41 ms 9104 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 77 ms 11028 KB Output is correct
12 Correct 104 ms 12908 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 3 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 3 ms 3448 KB Output is correct
20 Correct 3 ms 3452 KB Output is correct
21 Correct 3 ms 3352 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 3 ms 3432 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3404 KB Output is correct
28 Correct 3 ms 3404 KB Output is correct
29 Correct 3 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3456 KB Output is correct
34 Correct 3 ms 3404 KB Output is correct
35 Correct 2 ms 3452 KB Output is correct
36 Correct 3 ms 3532 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 3 ms 3404 KB Output is correct
39 Correct 59 ms 14916 KB Output is correct
40 Correct 62 ms 14984 KB Output is correct
41 Correct 41 ms 11168 KB Output is correct
42 Correct 10 ms 5128 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 3 ms 3404 KB Output is correct
45 Correct 3 ms 3448 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 3404 KB Output is correct
49 Correct 3 ms 3404 KB Output is correct
50 Correct 3 ms 3404 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 3404 KB Output is correct
54 Correct 3 ms 3404 KB Output is correct
55 Correct 3 ms 3404 KB Output is correct
56 Correct 3 ms 3404 KB Output is correct
57 Correct 96 ms 10620 KB Output is correct
58 Correct 112 ms 10692 KB Output is correct
59 Correct 94 ms 10668 KB Output is correct
60 Correct 78 ms 10640 KB Output is correct
61 Correct 86 ms 10632 KB Output is correct
62 Correct 99 ms 10800 KB Output is correct
63 Correct 92 ms 10408 KB Output is correct
64 Correct 76 ms 10344 KB Output is correct
65 Correct 77 ms 10692 KB Output is correct
66 Correct 90 ms 10600 KB Output is correct
67 Correct 74 ms 10564 KB Output is correct
68 Correct 85 ms 10616 KB Output is correct
69 Correct 81 ms 10944 KB Output is correct
70 Correct 109 ms 10960 KB Output is correct
71 Correct 3 ms 3440 KB Output is correct
72 Correct 4 ms 3592 KB Output is correct
73 Correct 4 ms 3660 KB Output is correct
74 Correct 4 ms 3588 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 3752 KB Output is correct
78 Correct 4 ms 3632 KB Output is correct
79 Correct 4 ms 3652 KB Output is correct
80 Correct 105 ms 10596 KB Output is correct
81 Correct 140 ms 10564 KB Output is correct
82 Correct 76 ms 10820 KB Output is correct
83 Correct 75 ms 10692 KB Output is correct
84 Correct 4 ms 3548 KB Output is correct
85 Correct 5 ms 3536 KB Output is correct
86 Correct 4 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 4 ms 3592 KB Output is correct
89 Correct 4 ms 3624 KB Output is correct
90 Correct 4 ms 3532 KB Output is correct
91 Correct 4 ms 3660 KB Output is correct
92 Correct 4 ms 3588 KB Output is correct
93 Correct 4 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 2 ms 3404 KB Output is correct
98 Correct 3 ms 3404 KB Output is correct
99 Correct 3 ms 3404 KB Output is correct
100 Correct 3 ms 3452 KB Output is correct
101 Correct 3 ms 3404 KB Output is correct
102 Correct 3 ms 3532 KB Output is correct
103 Correct 3 ms 3404 KB Output is correct
104 Correct 8 ms 4368 KB Output is correct
105 Correct 20 ms 5964 KB Output is correct
106 Correct 3 ms 3404 KB Output is correct
107 Correct 27 ms 7464 KB Output is correct
108 Correct 34 ms 9128 KB Output is correct
109 Correct 3 ms 3404 KB Output is correct
110 Correct 79 ms 11072 KB Output is correct
111 Correct 72 ms 12912 KB Output is correct
112 Correct 3 ms 3532 KB Output is correct
113 Correct 149 ms 16420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1066 ms 7044 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 3 ms 3404 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 4 ms 3404 KB Output is correct
6 Correct 3 ms 3448 KB Output is correct
7 Correct 3 ms 3452 KB Output is correct
8 Correct 3 ms 3352 KB Output is correct
9 Correct 3 ms 3404 KB Output is correct
10 Correct 3 ms 3404 KB Output is correct
11 Correct 3 ms 3432 KB Output is correct
12 Correct 3 ms 3404 KB Output is correct
13 Correct 3 ms 3404 KB Output is correct
14 Correct 3 ms 3404 KB Output is correct
15 Correct 3 ms 3404 KB Output is correct
16 Correct 3 ms 3404 KB Output is correct
17 Correct 3 ms 3404 KB Output is correct
18 Correct 3 ms 3404 KB Output is correct
19 Correct 3 ms 3404 KB Output is correct
20 Correct 3 ms 3456 KB Output is correct
21 Correct 3 ms 3404 KB Output is correct
22 Correct 2 ms 3452 KB Output is correct
23 Correct 3 ms 3532 KB Output is correct
24 Correct 3 ms 3404 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 4 ms 3404 KB Output is correct
27 Correct 6 ms 3532 KB Output is correct
28 Correct 14 ms 3532 KB Output is correct
29 Correct 4 ms 3460 KB Output is correct
30 Correct 6 ms 3532 KB Output is correct
31 Correct 9 ms 3660 KB Output is correct
32 Correct 4 ms 3524 KB Output is correct
33 Correct 7 ms 3588 KB Output is correct
34 Correct 9 ms 3660 KB Output is correct
35 Correct 2 ms 3456 KB Output is correct
36 Correct 2 ms 3404 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 2 ms 3404 KB Output is correct
39 Correct 4 ms 3404 KB Output is correct
40 Correct 3 ms 3404 KB Output is correct
41 Correct 3 ms 3404 KB Output is correct
42 Correct 2 ms 3404 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 3 ms 3404 KB Output is correct
45 Correct 3 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 3404 KB Output is correct
49 Correct 3 ms 3404 KB Output is correct
50 Correct 3 ms 3404 KB Output is correct
51 Correct 3 ms 3404 KB Output is correct
52 Incorrect 3 ms 3404 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 14916 KB Output is correct
2 Correct 76 ms 14960 KB Output is correct
3 Correct 44 ms 11264 KB Output is correct
4 Correct 12 ms 5068 KB Output is correct
5 Correct 8 ms 4300 KB Output is correct
6 Correct 15 ms 5964 KB Output is correct
7 Correct 3 ms 3404 KB Output is correct
8 Correct 29 ms 7436 KB Output is correct
9 Correct 41 ms 9104 KB Output is correct
10 Correct 3 ms 3532 KB Output is correct
11 Correct 77 ms 11028 KB Output is correct
12 Correct 104 ms 12908 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 3 ms 3404 KB Output is correct
17 Correct 2 ms 3404 KB Output is correct
18 Correct 4 ms 3404 KB Output is correct
19 Correct 3 ms 3448 KB Output is correct
20 Correct 3 ms 3452 KB Output is correct
21 Correct 3 ms 3352 KB Output is correct
22 Correct 3 ms 3404 KB Output is correct
23 Correct 3 ms 3404 KB Output is correct
24 Correct 3 ms 3432 KB Output is correct
25 Correct 3 ms 3404 KB Output is correct
26 Correct 3 ms 3404 KB Output is correct
27 Correct 3 ms 3404 KB Output is correct
28 Correct 3 ms 3404 KB Output is correct
29 Correct 3 ms 3404 KB Output is correct
30 Correct 3 ms 3404 KB Output is correct
31 Correct 3 ms 3404 KB Output is correct
32 Correct 3 ms 3404 KB Output is correct
33 Correct 3 ms 3456 KB Output is correct
34 Correct 3 ms 3404 KB Output is correct
35 Correct 2 ms 3452 KB Output is correct
36 Correct 3 ms 3532 KB Output is correct
37 Correct 3 ms 3404 KB Output is correct
38 Correct 3 ms 3404 KB Output is correct
39 Correct 59 ms 14916 KB Output is correct
40 Correct 62 ms 14984 KB Output is correct
41 Correct 41 ms 11168 KB Output is correct
42 Correct 10 ms 5128 KB Output is correct
43 Correct 3 ms 3404 KB Output is correct
44 Correct 3 ms 3404 KB Output is correct
45 Correct 3 ms 3448 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 3404 KB Output is correct
49 Correct 3 ms 3404 KB Output is correct
50 Correct 3 ms 3404 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 3404 KB Output is correct
54 Correct 3 ms 3404 KB Output is correct
55 Correct 3 ms 3404 KB Output is correct
56 Correct 3 ms 3404 KB Output is correct
57 Correct 96 ms 10620 KB Output is correct
58 Correct 112 ms 10692 KB Output is correct
59 Correct 94 ms 10668 KB Output is correct
60 Correct 78 ms 10640 KB Output is correct
61 Correct 86 ms 10632 KB Output is correct
62 Correct 99 ms 10800 KB Output is correct
63 Correct 92 ms 10408 KB Output is correct
64 Correct 76 ms 10344 KB Output is correct
65 Correct 77 ms 10692 KB Output is correct
66 Correct 90 ms 10600 KB Output is correct
67 Correct 74 ms 10564 KB Output is correct
68 Correct 85 ms 10616 KB Output is correct
69 Correct 81 ms 10944 KB Output is correct
70 Correct 109 ms 10960 KB Output is correct
71 Correct 3 ms 3440 KB Output is correct
72 Correct 4 ms 3592 KB Output is correct
73 Correct 4 ms 3660 KB Output is correct
74 Correct 4 ms 3588 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 3752 KB Output is correct
78 Correct 4 ms 3632 KB Output is correct
79 Correct 4 ms 3652 KB Output is correct
80 Correct 105 ms 10596 KB Output is correct
81 Correct 140 ms 10564 KB Output is correct
82 Correct 76 ms 10820 KB Output is correct
83 Correct 75 ms 10692 KB Output is correct
84 Correct 4 ms 3548 KB Output is correct
85 Correct 5 ms 3536 KB Output is correct
86 Correct 4 ms 3532 KB Output is correct
87 Correct 4 ms 3532 KB Output is correct
88 Correct 4 ms 3592 KB Output is correct
89 Correct 4 ms 3624 KB Output is correct
90 Correct 4 ms 3532 KB Output is correct
91 Correct 4 ms 3660 KB Output is correct
92 Correct 4 ms 3588 KB Output is correct
93 Correct 4 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 2 ms 3404 KB Output is correct
98 Correct 3 ms 3404 KB Output is correct
99 Correct 3 ms 3404 KB Output is correct
100 Correct 3 ms 3452 KB Output is correct
101 Correct 3 ms 3404 KB Output is correct
102 Correct 3 ms 3532 KB Output is correct
103 Correct 3 ms 3404 KB Output is correct
104 Correct 8 ms 4368 KB Output is correct
105 Correct 20 ms 5964 KB Output is correct
106 Correct 3 ms 3404 KB Output is correct
107 Correct 27 ms 7464 KB Output is correct
108 Correct 34 ms 9128 KB Output is correct
109 Correct 3 ms 3404 KB Output is correct
110 Correct 79 ms 11072 KB Output is correct
111 Correct 72 ms 12912 KB Output is correct
112 Correct 3 ms 3532 KB Output is correct
113 Correct 149 ms 16420 KB Output is correct
114 Execution timed out 1066 ms 7044 KB Time limit exceeded
115 Halted 0 ms 0 KB -