답안 #737856

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
737856 2023-05-07T20:50:09 Z BidoTeima 꿈 (IOI13_dreaming) C++17
47 / 100
100 ms 15084 KB
/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
#include "dreaming.h"
using namespace std;
using ll = long long; 
void moo(string filename);
void ACPLS(string str = "")
{
    if(str=="NOF")return;
    if(str.size() && str != "IIOT")
        moo(str);
    else if(str != "IIOT"){
#ifndef ONLINE_JUDGE
        freopen("output.txt", "w", stdout);
        freopen("input.txt", "r", stdin);
#endif
    }
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}
void moo(string fileName){
    freopen((fileName+".in").c_str(),"r",stdin);
    freopen((fileName+".out").c_str(),"w",stdout);
}
#define tcccc         \
    int tttttt/*,subtask*/;    \
    cin >> tttttt/* >> subtask*/; \
    while (tttttt--)/*end
*/ 
const int N = 1e5;
vector<pair<int,int>> adj[N];  
int cur_farthest_node, cur_farthest_node_dist;
bool vis[N];
vector<int>cc;
void set_farthest_node(int node, int prev, int cur_dist){
    vis[node] = 1;
    cc.push_back(node);
    if(adj[node].empty() || (adj[node].size() == 1 && prev != -1)){
        if(cur_dist > cur_farthest_node_dist){
            cur_farthest_node_dist = cur_dist;
            cur_farthest_node = node;
        }
        return;
    }
    for(auto& edge : adj[node]){
        if(edge.first != prev){
            set_farthest_node(edge.first, node, cur_dist + edge.second);
        }
    }
}
int dist[N][2];
void precompute_dist_dfs(int node, int prev, int cur_dist, bool b){
    dist[node][b] = cur_dist;
    for(auto& edge : adj[node]){
        if(edge.first != prev){
            precompute_dist_dfs(edge.first, node, cur_dist + edge.second, b);
        }
    }
}
void precompute_dist(int node, bool b){
    for(int i : cc)
        dist[i][b] = 1e9;
    precompute_dist_dfs(node, -1, 0, b);
}
int travelTime(int n, int m, int l, int a[], int b[], int t[])
{      
    for(int i = 0; i < m; i++){ 
        adj[a[i]].push_back({b[i], t[i]});
        adj[b[i]].push_back({a[i], t[i]});
    }
    multiset<pair<int, int>>ms;
    for(int i = 0; i < n; i++){
        if(vis[i])
            continue;
        cc.clear();
        cur_farthest_node_dist = -1;
        set_farthest_node(i, -1, 0);
        int e1 = cur_farthest_node;
        cur_farthest_node_dist = -1;
        set_farthest_node(e1, -1, 0);
        int e2 = cur_farthest_node;
        precompute_dist(e1, 0);
        precompute_dist(e2, 1);
        int root = e1, min_max_dist = dist[e2][0];
        assert(dist[e2][0] == dist[e1][1]); 
        for(int node : cc){
            if(max(dist[node][0], dist[node][1]) < min_max_dist){
                min_max_dist = max(dist[node][0], dist[node][1]);
                root = node;
            }
        }
        ms.insert({min_max_dist, dist[e2][0]});
    }
    while(ms.size() > 1){
        auto it1 = ms.begin(), it2 = next(ms.begin());
        int a = it1->first, b = it2->first, d1 = it1->second, d2 = it2->second;
        ms.erase(ms.begin());
        ms.erase(ms.begin());
        ms.insert({max(b, a + l), max({d1, d2, a + b + l})});
    }
    return ms.begin()->second;
}

Compilation message

dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:89:13: warning: variable 'root' set but not used [-Wunused-but-set-variable]
   89 |         int root = e1, min_max_dist = dist[e2][0];
      |             ^~~~
dreaming.cpp: In function 'void ACPLS(std::string)':
dreaming.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:19:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void moo(std::string)':
dreaming.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |     freopen((fileName+".in").c_str(),"r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dreaming.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   28 |     freopen((fileName+".out").c_str(),"w",stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 13896 KB Output is correct
2 Correct 50 ms 13916 KB Output is correct
3 Correct 30 ms 10156 KB Output is correct
4 Correct 7 ms 4468 KB Output is correct
5 Correct 7 ms 3668 KB Output is correct
6 Correct 14 ms 5232 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 23 ms 6652 KB Output is correct
9 Correct 30 ms 8240 KB Output is correct
10 Correct 2 ms 2672 KB Output is correct
11 Correct 62 ms 9884 KB Output is correct
12 Correct 67 ms 11848 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2580 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2664 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2664 KB Output is correct
12 Correct 2 ms 2660 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 3 ms 2660 KB Output is correct
23 Correct 2 ms 2664 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 13896 KB Output is correct
2 Correct 50 ms 13916 KB Output is correct
3 Correct 30 ms 10156 KB Output is correct
4 Correct 7 ms 4468 KB Output is correct
5 Correct 7 ms 3668 KB Output is correct
6 Correct 14 ms 5232 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 23 ms 6652 KB Output is correct
9 Correct 30 ms 8240 KB Output is correct
10 Correct 2 ms 2672 KB Output is correct
11 Correct 62 ms 9884 KB Output is correct
12 Correct 67 ms 11848 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2580 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2664 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2664 KB Output is correct
25 Correct 2 ms 2660 KB Output is correct
26 Correct 2 ms 2668 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 3 ms 2644 KB Output is correct
35 Correct 3 ms 2660 KB Output is correct
36 Correct 2 ms 2664 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 46 ms 14020 KB Output is correct
40 Correct 47 ms 14036 KB Output is correct
41 Correct 30 ms 10160 KB Output is correct
42 Correct 8 ms 4564 KB Output is correct
43 Correct 2 ms 2664 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2664 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 2 ms 2660 KB Output is correct
54 Correct 2 ms 2664 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 77 ms 9624 KB Output is correct
58 Correct 78 ms 9284 KB Output is correct
59 Correct 70 ms 9536 KB Output is correct
60 Correct 65 ms 9276 KB Output is correct
61 Correct 62 ms 9496 KB Output is correct
62 Correct 100 ms 9180 KB Output is correct
63 Correct 74 ms 9412 KB Output is correct
64 Correct 69 ms 9376 KB Output is correct
65 Correct 63 ms 9344 KB Output is correct
66 Correct 64 ms 9408 KB Output is correct
67 Correct 65 ms 9532 KB Output is correct
68 Correct 80 ms 9536 KB Output is correct
69 Correct 83 ms 9276 KB Output is correct
70 Correct 66 ms 9284 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 3 ms 2800 KB Output is correct
73 Correct 3 ms 2932 KB Output is correct
74 Correct 3 ms 2900 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 3 ms 2844 KB Output is correct
78 Correct 3 ms 2900 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 69 ms 9796 KB Output is correct
81 Correct 65 ms 9280 KB Output is correct
82 Correct 65 ms 9460 KB Output is correct
83 Correct 78 ms 9460 KB Output is correct
84 Correct 3 ms 2772 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2772 KB Output is correct
87 Correct 3 ms 2772 KB Output is correct
88 Correct 3 ms 2772 KB Output is correct
89 Correct 3 ms 2772 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2928 KB Output is correct
92 Correct 3 ms 2900 KB Output is correct
93 Correct 3 ms 2900 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 2 ms 2644 KB Output is correct
96 Correct 2 ms 2660 KB Output is correct
97 Correct 2 ms 2664 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 2 ms 2644 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 2 ms 2644 KB Output is correct
102 Correct 1 ms 2656 KB Output is correct
103 Correct 2 ms 2660 KB Output is correct
104 Correct 7 ms 3668 KB Output is correct
105 Correct 13 ms 5304 KB Output is correct
106 Correct 2 ms 2664 KB Output is correct
107 Correct 23 ms 6612 KB Output is correct
108 Correct 30 ms 8284 KB Output is correct
109 Correct 2 ms 2644 KB Output is correct
110 Correct 43 ms 9852 KB Output is correct
111 Correct 53 ms 11908 KB Output is correct
112 Correct 3 ms 2772 KB Output is correct
113 Correct 96 ms 15084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8724 KB Output is correct
2 Incorrect 43 ms 8864 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2580 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2664 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2664 KB Output is correct
12 Correct 2 ms 2660 KB Output is correct
13 Correct 2 ms 2668 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 3 ms 2644 KB Output is correct
22 Correct 3 ms 2660 KB Output is correct
23 Correct 2 ms 2664 KB Output is correct
24 Correct 2 ms 2644 KB Output is correct
25 Correct 2 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 3 ms 2772 KB Output is correct
28 Correct 3 ms 2804 KB Output is correct
29 Incorrect 3 ms 2644 KB Output isn't correct
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 43 ms 13896 KB Output is correct
2 Correct 50 ms 13916 KB Output is correct
3 Correct 30 ms 10156 KB Output is correct
4 Correct 7 ms 4468 KB Output is correct
5 Correct 7 ms 3668 KB Output is correct
6 Correct 14 ms 5232 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 23 ms 6652 KB Output is correct
9 Correct 30 ms 8240 KB Output is correct
10 Correct 2 ms 2672 KB Output is correct
11 Correct 62 ms 9884 KB Output is correct
12 Correct 67 ms 11848 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2580 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2664 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2664 KB Output is correct
25 Correct 2 ms 2660 KB Output is correct
26 Correct 2 ms 2668 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 2 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2644 KB Output is correct
31 Correct 2 ms 2644 KB Output is correct
32 Correct 2 ms 2644 KB Output is correct
33 Correct 2 ms 2644 KB Output is correct
34 Correct 3 ms 2644 KB Output is correct
35 Correct 3 ms 2660 KB Output is correct
36 Correct 2 ms 2664 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 2 ms 2644 KB Output is correct
39 Correct 46 ms 14020 KB Output is correct
40 Correct 47 ms 14036 KB Output is correct
41 Correct 30 ms 10160 KB Output is correct
42 Correct 8 ms 4564 KB Output is correct
43 Correct 2 ms 2664 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 2 ms 2644 KB Output is correct
46 Correct 2 ms 2644 KB Output is correct
47 Correct 2 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2644 KB Output is correct
50 Correct 2 ms 2664 KB Output is correct
51 Correct 2 ms 2644 KB Output is correct
52 Correct 2 ms 2644 KB Output is correct
53 Correct 2 ms 2660 KB Output is correct
54 Correct 2 ms 2664 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 2 ms 2644 KB Output is correct
57 Correct 77 ms 9624 KB Output is correct
58 Correct 78 ms 9284 KB Output is correct
59 Correct 70 ms 9536 KB Output is correct
60 Correct 65 ms 9276 KB Output is correct
61 Correct 62 ms 9496 KB Output is correct
62 Correct 100 ms 9180 KB Output is correct
63 Correct 74 ms 9412 KB Output is correct
64 Correct 69 ms 9376 KB Output is correct
65 Correct 63 ms 9344 KB Output is correct
66 Correct 64 ms 9408 KB Output is correct
67 Correct 65 ms 9532 KB Output is correct
68 Correct 80 ms 9536 KB Output is correct
69 Correct 83 ms 9276 KB Output is correct
70 Correct 66 ms 9284 KB Output is correct
71 Correct 2 ms 2644 KB Output is correct
72 Correct 3 ms 2800 KB Output is correct
73 Correct 3 ms 2932 KB Output is correct
74 Correct 3 ms 2900 KB Output is correct
75 Correct 3 ms 2900 KB Output is correct
76 Correct 3 ms 2900 KB Output is correct
77 Correct 3 ms 2844 KB Output is correct
78 Correct 3 ms 2900 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 69 ms 9796 KB Output is correct
81 Correct 65 ms 9280 KB Output is correct
82 Correct 65 ms 9460 KB Output is correct
83 Correct 78 ms 9460 KB Output is correct
84 Correct 3 ms 2772 KB Output is correct
85 Correct 3 ms 2772 KB Output is correct
86 Correct 3 ms 2772 KB Output is correct
87 Correct 3 ms 2772 KB Output is correct
88 Correct 3 ms 2772 KB Output is correct
89 Correct 3 ms 2772 KB Output is correct
90 Correct 3 ms 2772 KB Output is correct
91 Correct 3 ms 2928 KB Output is correct
92 Correct 3 ms 2900 KB Output is correct
93 Correct 3 ms 2900 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 2 ms 2644 KB Output is correct
96 Correct 2 ms 2660 KB Output is correct
97 Correct 2 ms 2664 KB Output is correct
98 Correct 2 ms 2644 KB Output is correct
99 Correct 2 ms 2644 KB Output is correct
100 Correct 2 ms 2644 KB Output is correct
101 Correct 2 ms 2644 KB Output is correct
102 Correct 1 ms 2656 KB Output is correct
103 Correct 2 ms 2660 KB Output is correct
104 Correct 7 ms 3668 KB Output is correct
105 Correct 13 ms 5304 KB Output is correct
106 Correct 2 ms 2664 KB Output is correct
107 Correct 23 ms 6612 KB Output is correct
108 Correct 30 ms 8284 KB Output is correct
109 Correct 2 ms 2644 KB Output is correct
110 Correct 43 ms 9852 KB Output is correct
111 Correct 53 ms 11908 KB Output is correct
112 Correct 3 ms 2772 KB Output is correct
113 Correct 96 ms 15084 KB Output is correct
114 Correct 42 ms 8724 KB Output is correct
115 Incorrect 43 ms 8864 KB Output isn't correct
116 Halted 0 ms 0 KB -