Submission #778008

# Submission time Handle Problem Language Result Execution time Memory
778008 2023-07-10T02:31:01 Z Cookie Dreaming (IOI13_dreaming) C++14
47 / 100
1000 ms 15972 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#include <stdio.h>
#include <stdlib.h>
const ll inf = 1e9 + 6;
#include "dreaming.h"
const int mxn = 1e5 + 5;
vt<pii>adj[mxn + 1];
int n;
bool vis[mxn + 1];
vt<int>comp;
vt<ll>bfs(int s){
    // bfs works since it is a tree
    vt<ll>dis(n + 1, -1); 
    queue<int>q; q.push(s); dis[s] = 0;
    while(!q.empty()){
        int nw = q.front(); q.pop();
        for(auto [v, w]: adj[nw]){
            if(dis[v] == -1){
                dis[v] = dis[nw] + w;
                q.push(v);
            }
        }
    }
    return(dis);
}
void dfs(int s){
    vis[s] = 1; comp.pb(s);
    for(auto [v, w]: adj[s]){
        if(!vis[v]){
            dfs(v); 
        }
    }
}
int travelTime(int N, int m, int L, int A[], int B[], int T[]) {
    n = N;
    forr(i, 0, m){
        int u = A[i], v = B[i], w = T[i];
        adj[u].pb({v, w}); adj[v].pb({u, w});
    }
    ll ans = 0, diam = 0;
    forr(i, 1, n + 1){
        if(!vis[i]){
            comp.clear();
            vt<ll>d1 = bfs(i);
            int id = max_element(d1.begin(), d1.end()) - d1.begin();
            vt<ll>d2 = bfs(id);
            int id2 = max_element(d2.begin(), d2.end()) - d2.begin();
            vt<ll>d3 = bfs(id2);
            diam = max(diam, *max_element(d3.begin(), d3.end()));
            dfs(i);
            ll mn = inf, idd = -1;
            for(auto j: comp){
                ll val = max(d2[j], d3[j]);
                if(val < mn){
                    mn = val; idd = j;
                }
            }
            ans += mn;
        }
    }
    ans += L;
    return(max(ans, diam));
}
/*
#define fail(s, x...) do { \
		fprintf(stderr, s "\n", ## x); \
		exit(1); \
	} while(0)
 
#define MAX_N 100000
 
static int A[MAX_N];
static int B[MAX_N];
static int T[MAX_N];
 
int main() {
	int N, M, L, i;
	int res;
    
	FILE *f = fopen("dreaming.in", "r");
	if (!f)
		fail("Failed to open input file.");
    
	res = scanf("%d%d%d", &N, &M, &L);
	for (i = 0; i < M; i++)
		res = scanf("%d%d%d", &A[i], &B[i], &T[i]);
	
 
	int answer = travelTime(N, M, L, A, B, T);
	printf("%d\n", answer);
 
	return 0;
}
*/

Compilation message

dreaming.cpp: In function 'std::vector<long long int> bfs(int)':
dreaming.cpp:33:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |         for(auto [v, w]: adj[nw]){
      |                  ^
dreaming.cpp: In function 'void dfs(int)':
dreaming.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   44 |     for(auto [v, w]: adj[s]){
      |              ^
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:67:26: warning: variable 'idd' set but not used [-Wunused-but-set-variable]
   67 |             ll mn = inf, idd = -1;
      |                          ^~~
# Verdict Execution time Memory Grader output
1 Correct 36 ms 13788 KB Output is correct
2 Correct 43 ms 14412 KB Output is correct
3 Correct 26 ms 9624 KB Output is correct
4 Correct 6 ms 4232 KB Output is correct
5 Correct 6 ms 3688 KB Output is correct
6 Correct 11 ms 5364 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 20 ms 6980 KB Output is correct
9 Correct 25 ms 8728 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 35 ms 10832 KB Output is correct
12 Correct 40 ms 12840 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2672 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2676 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2672 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2672 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 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 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 13788 KB Output is correct
2 Correct 43 ms 14412 KB Output is correct
3 Correct 26 ms 9624 KB Output is correct
4 Correct 6 ms 4232 KB Output is correct
5 Correct 6 ms 3688 KB Output is correct
6 Correct 11 ms 5364 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 20 ms 6980 KB Output is correct
9 Correct 25 ms 8728 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 35 ms 10832 KB Output is correct
12 Correct 40 ms 12840 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2672 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 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 2676 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 2 ms 2672 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2672 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 38 ms 13796 KB Output is correct
40 Correct 43 ms 14436 KB Output is correct
41 Correct 24 ms 9656 KB Output is correct
42 Correct 6 ms 4180 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 1 ms 2672 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2668 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 2 ms 2668 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 46 ms 12160 KB Output is correct
58 Correct 47 ms 11912 KB Output is correct
59 Correct 46 ms 12088 KB Output is correct
60 Correct 47 ms 11876 KB Output is correct
61 Correct 44 ms 12164 KB Output is correct
62 Correct 48 ms 11996 KB Output is correct
63 Correct 43 ms 11900 KB Output is correct
64 Correct 42 ms 11964 KB Output is correct
65 Correct 45 ms 12232 KB Output is correct
66 Correct 42 ms 12184 KB Output is correct
67 Correct 45 ms 12152 KB Output is correct
68 Correct 47 ms 12104 KB Output is correct
69 Correct 60 ms 12112 KB Output is correct
70 Correct 47 ms 12028 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 3 ms 2852 KB Output is correct
73 Correct 3 ms 2940 KB Output is correct
74 Correct 3 ms 2944 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 2940 KB Output is correct
78 Correct 3 ms 2852 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 44 ms 12084 KB Output is correct
81 Correct 44 ms 12116 KB Output is correct
82 Correct 45 ms 12228 KB Output is correct
83 Correct 46 ms 12188 KB Output is correct
84 Correct 2 ms 2900 KB Output is correct
85 Correct 2 ms 2772 KB Output is correct
86 Correct 2 ms 2844 KB Output is correct
87 Correct 2 ms 2900 KB Output is correct
88 Correct 3 ms 2900 KB Output is correct
89 Correct 2 ms 2900 KB Output is correct
90 Correct 3 ms 2900 KB Output is correct
91 Correct 3 ms 2940 KB Output is correct
92 Correct 2 ms 2900 KB Output is correct
93 Correct 2 ms 2900 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 1 ms 2644 KB Output is correct
96 Correct 2 ms 2648 KB Output is correct
97 Correct 2 ms 2644 KB Output is correct
98 Correct 1 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 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 1 ms 2644 KB Output is correct
104 Correct 6 ms 3668 KB Output is correct
105 Correct 11 ms 5364 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 22 ms 6976 KB Output is correct
108 Correct 24 ms 8692 KB Output is correct
109 Correct 2 ms 2648 KB Output is correct
110 Correct 35 ms 10796 KB Output is correct
111 Correct 39 ms 12856 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 53 ms 15972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1082 ms 7712 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2672 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 2 ms 2644 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2676 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2672 KB Output is correct
13 Correct 1 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 1 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2672 KB Output is correct
18 Correct 1 ms 2644 KB Output is correct
19 Correct 1 ms 2644 KB Output is correct
20 Correct 1 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 2644 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 3 ms 2680 KB Output is correct
27 Correct 6 ms 2772 KB Output is correct
28 Correct 11 ms 2944 KB Output is correct
29 Incorrect 3 ms 2644 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 36 ms 13788 KB Output is correct
2 Correct 43 ms 14412 KB Output is correct
3 Correct 26 ms 9624 KB Output is correct
4 Correct 6 ms 4232 KB Output is correct
5 Correct 6 ms 3688 KB Output is correct
6 Correct 11 ms 5364 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 20 ms 6980 KB Output is correct
9 Correct 25 ms 8728 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 35 ms 10832 KB Output is correct
12 Correct 40 ms 12840 KB Output is correct
13 Correct 2 ms 2772 KB Output is correct
14 Correct 2 ms 2672 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 1 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 2676 KB Output is correct
21 Correct 2 ms 2644 KB Output is correct
22 Correct 2 ms 2644 KB Output is correct
23 Correct 1 ms 2644 KB Output is correct
24 Correct 1 ms 2644 KB Output is correct
25 Correct 2 ms 2672 KB Output is correct
26 Correct 1 ms 2644 KB Output is correct
27 Correct 2 ms 2644 KB Output is correct
28 Correct 1 ms 2644 KB Output is correct
29 Correct 2 ms 2644 KB Output is correct
30 Correct 2 ms 2672 KB Output is correct
31 Correct 1 ms 2644 KB Output is correct
32 Correct 1 ms 2644 KB Output is correct
33 Correct 1 ms 2644 KB Output is correct
34 Correct 2 ms 2644 KB Output is correct
35 Correct 2 ms 2644 KB Output is correct
36 Correct 2 ms 2644 KB Output is correct
37 Correct 2 ms 2644 KB Output is correct
38 Correct 1 ms 2644 KB Output is correct
39 Correct 38 ms 13796 KB Output is correct
40 Correct 43 ms 14436 KB Output is correct
41 Correct 24 ms 9656 KB Output is correct
42 Correct 6 ms 4180 KB Output is correct
43 Correct 1 ms 2644 KB Output is correct
44 Correct 2 ms 2644 KB Output is correct
45 Correct 1 ms 2644 KB Output is correct
46 Correct 1 ms 2672 KB Output is correct
47 Correct 1 ms 2644 KB Output is correct
48 Correct 2 ms 2644 KB Output is correct
49 Correct 2 ms 2668 KB Output is correct
50 Correct 2 ms 2644 KB Output is correct
51 Correct 1 ms 2644 KB Output is correct
52 Correct 1 ms 2644 KB Output is correct
53 Correct 2 ms 2668 KB Output is correct
54 Correct 1 ms 2644 KB Output is correct
55 Correct 2 ms 2644 KB Output is correct
56 Correct 1 ms 2644 KB Output is correct
57 Correct 46 ms 12160 KB Output is correct
58 Correct 47 ms 11912 KB Output is correct
59 Correct 46 ms 12088 KB Output is correct
60 Correct 47 ms 11876 KB Output is correct
61 Correct 44 ms 12164 KB Output is correct
62 Correct 48 ms 11996 KB Output is correct
63 Correct 43 ms 11900 KB Output is correct
64 Correct 42 ms 11964 KB Output is correct
65 Correct 45 ms 12232 KB Output is correct
66 Correct 42 ms 12184 KB Output is correct
67 Correct 45 ms 12152 KB Output is correct
68 Correct 47 ms 12104 KB Output is correct
69 Correct 60 ms 12112 KB Output is correct
70 Correct 47 ms 12028 KB Output is correct
71 Correct 1 ms 2644 KB Output is correct
72 Correct 3 ms 2852 KB Output is correct
73 Correct 3 ms 2940 KB Output is correct
74 Correct 3 ms 2944 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 2940 KB Output is correct
78 Correct 3 ms 2852 KB Output is correct
79 Correct 3 ms 2900 KB Output is correct
80 Correct 44 ms 12084 KB Output is correct
81 Correct 44 ms 12116 KB Output is correct
82 Correct 45 ms 12228 KB Output is correct
83 Correct 46 ms 12188 KB Output is correct
84 Correct 2 ms 2900 KB Output is correct
85 Correct 2 ms 2772 KB Output is correct
86 Correct 2 ms 2844 KB Output is correct
87 Correct 2 ms 2900 KB Output is correct
88 Correct 3 ms 2900 KB Output is correct
89 Correct 2 ms 2900 KB Output is correct
90 Correct 3 ms 2900 KB Output is correct
91 Correct 3 ms 2940 KB Output is correct
92 Correct 2 ms 2900 KB Output is correct
93 Correct 2 ms 2900 KB Output is correct
94 Correct 2 ms 2644 KB Output is correct
95 Correct 1 ms 2644 KB Output is correct
96 Correct 2 ms 2648 KB Output is correct
97 Correct 2 ms 2644 KB Output is correct
98 Correct 1 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 1 ms 2644 KB Output is correct
102 Correct 1 ms 2644 KB Output is correct
103 Correct 1 ms 2644 KB Output is correct
104 Correct 6 ms 3668 KB Output is correct
105 Correct 11 ms 5364 KB Output is correct
106 Correct 2 ms 2644 KB Output is correct
107 Correct 22 ms 6976 KB Output is correct
108 Correct 24 ms 8692 KB Output is correct
109 Correct 2 ms 2648 KB Output is correct
110 Correct 35 ms 10796 KB Output is correct
111 Correct 39 ms 12856 KB Output is correct
112 Correct 2 ms 2772 KB Output is correct
113 Correct 53 ms 15972 KB Output is correct
114 Execution timed out 1082 ms 7712 KB Time limit exceeded
115 Halted 0 ms 0 KB -