답안 #521318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521318 2022-02-01T16:47:47 Z Urvuk3 꿈 (IOI13_dreaming) C++17
47 / 100
502 ms 46356 KB
#include "dreaming.h"
#include <bits/stdc++.h>

using namespace std;

#define ll long long
const ll INF=1e9,LINF=1e18;
#define fi first
#define se second
#define pii pair<int,int>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define PRINT(x) cerr<<#x<<'='<<x<<endl;
#define pb push_back
#define PRINTvec(arr) { cerr<<#arr<<"="; for(auto h:arr) cerr<<h<<" "; cerr<<endl; }

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
    vector<int> adj[N+1];
    map<pair<int,int>,ll> edge;
    for(int i=0;i<M;i++){
        int u=A[i],v=B[i];
        ll w=T[i];
        u++; v++;
        adj[u].pb(v);
        adj[v].pb(u);
        edge[{u,v}]=w;
        edge[{v,u}]=w;
    }
    vector<int> trees[N+1];
    vector<bool> vis(N+1,false);
    int idx=1;
    function<void(int,int)> dfs=[&](int node,int prev){
        vis[node]=true;
        trees[idx].pb(node);
        for(auto v:adj[node]) if(v!=prev) dfs(v,node);
    };
    for(int i=1;i<=N;i++){
        if(!vis[i]){
            dfs(i,-1);
            idx++;
        }
    }
    vector<ll> nadstablo_udaljenost(N+1),podstablo_udaljenost1(N+1),podstablo_udaljenost2(N+1);
    vector<ll> udaljenost(N+1),dubina(N+1);
    function<void(int,int)> dfs1=[&](int node,int prev){
        podstablo_udaljenost1[node]=0; podstablo_udaljenost2[node]=0;
        if(prev!=-1) dubina[node]=dubina[prev]+1;
        else dubina[node]=0;
        vector<ll> tmp; tmp.pb(0); tmp.pb(0);
        for(auto v:adj[node]){
            if(v!=prev){
                dfs1(v,node);
                tmp.pb(podstablo_udaljenost1[v]+edge[{node,v}]);
            }
        }
        sort(all(tmp),greater<int>());
        podstablo_udaljenost1[node]=tmp[0]; podstablo_udaljenost2[node]=tmp[1];
    };
    function<void(int,int)> dfs2=[&](int node,int prev){
        nadstablo_udaljenost[node]=0;
        if(prev!=-1){
            nadstablo_udaljenost[node]=nadstablo_udaljenost[prev]+edge[{prev,node}];
        }
        for(auto v:adj[prev]){
            if(dubina[v]>dubina[prev] && v!=node){
                nadstablo_udaljenost[node]=max(nadstablo_udaljenost[node],podstablo_udaljenost1[v]+edge[{v,prev}]+edge[{prev,node}]);
            }
        }
        for(auto v:adj[node]) if(v!=prev) dfs2(v,node);
        udaljenost[node]=max(nadstablo_udaljenost[node],podstablo_udaljenost1[node]);
    };
    int node=0; ll val=LINF;
    for(int i=1;i<idx;i++){
        int root=trees[i][0];
        dfs1(root,-1);
        dfs2(root,-1);
        if(i==1){
            for(auto v:trees[i]){
                if(udaljenost[v]<=val){
                    val=udaljenost[v]; node=v;
                }
            }
        }
        else{
            int tmp_node=0,tmp_val=INF;
            for(auto v:trees[i]){
                if(udaljenost[v]<=tmp_val){
                    tmp_val=udaljenost[v]; tmp_node=v;
                }
            }
            adj[tmp_node].pb(node); adj[node].pb(tmp_node);
            edge[{tmp_node,node}]=L; edge[{node,tmp_node}]=L;
        }
    }
    /*
    for(int i=1;i<idx;i++){
        PRINTvec(trees[i]);
        for(auto v:trees[i]){
            cout<<"nadstablo_udaljenost["<<v<<"]="<<nadstablo_udaljenost[v]<<endl;
            cout<<"podstablo_udaljenost1["<<v<<"]="<<podstablo_udaljenost1[v]<<endl;
            cout<<"podstablo_udaljenost2["<<v<<"]="<<podstablo_udaljenost2[v]<<endl;
            cout<<"udaljenost["<<v<<"]="<<udaljenost[v]<<endl;
            cout<<"dubina["<<v<<"]="<<dubina[v]<<endl;
            cout<<endl;
        }
        cout<<endl<<endl;
    }
    */
    dfs1(1,-1);
    ll diametar=0;
    for(int node=1;node<=N;node++){
        diametar=max(diametar,podstablo_udaljenost1[node]+podstablo_udaljenost2[node]);
    }
    return diametar;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 34236 KB Output is correct
2 Correct 344 ms 33452 KB Output is correct
3 Correct 184 ms 26288 KB Output is correct
4 Correct 23 ms 5252 KB Output is correct
5 Correct 19 ms 3508 KB Output is correct
6 Correct 45 ms 7856 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 118 ms 14652 KB Output is correct
9 Correct 176 ms 21200 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 290 ms 25264 KB Output is correct
12 Correct 348 ms 29604 KB Output is correct
13 Correct 2 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 34236 KB Output is correct
2 Correct 344 ms 33452 KB Output is correct
3 Correct 184 ms 26288 KB Output is correct
4 Correct 23 ms 5252 KB Output is correct
5 Correct 19 ms 3508 KB Output is correct
6 Correct 45 ms 7856 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 118 ms 14652 KB Output is correct
9 Correct 176 ms 21200 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 290 ms 25264 KB Output is correct
12 Correct 348 ms 29604 KB Output is correct
13 Correct 2 ms 588 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 216 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 319 ms 34212 KB Output is correct
40 Correct 328 ms 33448 KB Output is correct
41 Correct 177 ms 26176 KB Output is correct
42 Correct 27 ms 5444 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 296 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 464 ms 26384 KB Output is correct
58 Correct 462 ms 26308 KB Output is correct
59 Correct 495 ms 26584 KB Output is correct
60 Correct 497 ms 26624 KB Output is correct
61 Correct 480 ms 26428 KB Output is correct
62 Correct 478 ms 26584 KB Output is correct
63 Correct 478 ms 26428 KB Output is correct
64 Correct 483 ms 26588 KB Output is correct
65 Correct 486 ms 26504 KB Output is correct
66 Correct 471 ms 26428 KB Output is correct
67 Correct 478 ms 26532 KB Output is correct
68 Correct 480 ms 26612 KB Output is correct
69 Correct 486 ms 26764 KB Output is correct
70 Correct 476 ms 26676 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 6 ms 1100 KB Output is correct
73 Correct 6 ms 1100 KB Output is correct
74 Correct 6 ms 1132 KB Output is correct
75 Correct 6 ms 1100 KB Output is correct
76 Correct 5 ms 1100 KB Output is correct
77 Correct 5 ms 1080 KB Output is correct
78 Correct 6 ms 1084 KB Output is correct
79 Correct 6 ms 1100 KB Output is correct
80 Correct 488 ms 26648 KB Output is correct
81 Correct 478 ms 26692 KB Output is correct
82 Correct 502 ms 26424 KB Output is correct
83 Correct 483 ms 26428 KB Output is correct
84 Correct 31 ms 844 KB Output is correct
85 Correct 24 ms 844 KB Output is correct
86 Correct 17 ms 972 KB Output is correct
87 Correct 5 ms 1044 KB Output is correct
88 Correct 20 ms 972 KB Output is correct
89 Correct 19 ms 972 KB Output is correct
90 Correct 6 ms 972 KB Output is correct
91 Correct 6 ms 1100 KB Output is correct
92 Correct 6 ms 972 KB Output is correct
93 Correct 14 ms 1044 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 1 ms 332 KB Output is correct
98 Correct 1 ms 332 KB Output is correct
99 Correct 1 ms 332 KB Output is correct
100 Correct 1 ms 332 KB Output is correct
101 Correct 1 ms 332 KB Output is correct
102 Correct 1 ms 332 KB Output is correct
103 Correct 1 ms 332 KB Output is correct
104 Correct 19 ms 3540 KB Output is correct
105 Correct 46 ms 7736 KB Output is correct
106 Correct 1 ms 332 KB Output is correct
107 Correct 122 ms 14616 KB Output is correct
108 Correct 175 ms 21184 KB Output is correct
109 Correct 2 ms 588 KB Output is correct
110 Correct 309 ms 25188 KB Output is correct
111 Correct 359 ms 29628 KB Output is correct
112 Correct 2 ms 568 KB Output is correct
113 Correct 484 ms 46356 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 197 ms 26468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 300 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 216 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 300 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 0 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 4 ms 460 KB Output is correct
27 Correct 8 ms 844 KB Output is correct
28 Correct 15 ms 1060 KB Output is correct
29 Incorrect 3 ms 460 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 334 ms 34236 KB Output is correct
2 Correct 344 ms 33452 KB Output is correct
3 Correct 184 ms 26288 KB Output is correct
4 Correct 23 ms 5252 KB Output is correct
5 Correct 19 ms 3508 KB Output is correct
6 Correct 45 ms 7856 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 118 ms 14652 KB Output is correct
9 Correct 176 ms 21200 KB Output is correct
10 Correct 1 ms 588 KB Output is correct
11 Correct 290 ms 25264 KB Output is correct
12 Correct 348 ms 29604 KB Output is correct
13 Correct 2 ms 588 KB Output is correct
14 Correct 1 ms 300 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 300 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 216 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
29 Correct 1 ms 204 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 300 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 300 KB Output is correct
37 Correct 0 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 319 ms 34212 KB Output is correct
40 Correct 328 ms 33448 KB Output is correct
41 Correct 177 ms 26176 KB Output is correct
42 Correct 27 ms 5444 KB Output is correct
43 Correct 1 ms 332 KB Output is correct
44 Correct 1 ms 332 KB Output is correct
45 Correct 1 ms 332 KB Output is correct
46 Correct 1 ms 332 KB Output is correct
47 Correct 1 ms 296 KB Output is correct
48 Correct 1 ms 332 KB Output is correct
49 Correct 1 ms 332 KB Output is correct
50 Correct 1 ms 296 KB Output is correct
51 Correct 1 ms 204 KB Output is correct
52 Correct 1 ms 204 KB Output is correct
53 Correct 1 ms 332 KB Output is correct
54 Correct 0 ms 204 KB Output is correct
55 Correct 1 ms 332 KB Output is correct
56 Correct 1 ms 332 KB Output is correct
57 Correct 464 ms 26384 KB Output is correct
58 Correct 462 ms 26308 KB Output is correct
59 Correct 495 ms 26584 KB Output is correct
60 Correct 497 ms 26624 KB Output is correct
61 Correct 480 ms 26428 KB Output is correct
62 Correct 478 ms 26584 KB Output is correct
63 Correct 478 ms 26428 KB Output is correct
64 Correct 483 ms 26588 KB Output is correct
65 Correct 486 ms 26504 KB Output is correct
66 Correct 471 ms 26428 KB Output is correct
67 Correct 478 ms 26532 KB Output is correct
68 Correct 480 ms 26612 KB Output is correct
69 Correct 486 ms 26764 KB Output is correct
70 Correct 476 ms 26676 KB Output is correct
71 Correct 0 ms 204 KB Output is correct
72 Correct 6 ms 1100 KB Output is correct
73 Correct 6 ms 1100 KB Output is correct
74 Correct 6 ms 1132 KB Output is correct
75 Correct 6 ms 1100 KB Output is correct
76 Correct 5 ms 1100 KB Output is correct
77 Correct 5 ms 1080 KB Output is correct
78 Correct 6 ms 1084 KB Output is correct
79 Correct 6 ms 1100 KB Output is correct
80 Correct 488 ms 26648 KB Output is correct
81 Correct 478 ms 26692 KB Output is correct
82 Correct 502 ms 26424 KB Output is correct
83 Correct 483 ms 26428 KB Output is correct
84 Correct 31 ms 844 KB Output is correct
85 Correct 24 ms 844 KB Output is correct
86 Correct 17 ms 972 KB Output is correct
87 Correct 5 ms 1044 KB Output is correct
88 Correct 20 ms 972 KB Output is correct
89 Correct 19 ms 972 KB Output is correct
90 Correct 6 ms 972 KB Output is correct
91 Correct 6 ms 1100 KB Output is correct
92 Correct 6 ms 972 KB Output is correct
93 Correct 14 ms 1044 KB Output is correct
94 Correct 1 ms 332 KB Output is correct
95 Correct 1 ms 204 KB Output is correct
96 Correct 1 ms 332 KB Output is correct
97 Correct 1 ms 332 KB Output is correct
98 Correct 1 ms 332 KB Output is correct
99 Correct 1 ms 332 KB Output is correct
100 Correct 1 ms 332 KB Output is correct
101 Correct 1 ms 332 KB Output is correct
102 Correct 1 ms 332 KB Output is correct
103 Correct 1 ms 332 KB Output is correct
104 Correct 19 ms 3540 KB Output is correct
105 Correct 46 ms 7736 KB Output is correct
106 Correct 1 ms 332 KB Output is correct
107 Correct 122 ms 14616 KB Output is correct
108 Correct 175 ms 21184 KB Output is correct
109 Correct 2 ms 588 KB Output is correct
110 Correct 309 ms 25188 KB Output is correct
111 Correct 359 ms 29628 KB Output is correct
112 Correct 2 ms 568 KB Output is correct
113 Correct 484 ms 46356 KB Output is correct
114 Incorrect 197 ms 26468 KB Output isn't correct
115 Halted 0 ms 0 KB -