Submission #927553

# Submission time Handle Problem Language Result Execution time Memory
927553 2024-02-15T04:08:52 Z Cutebol Dreaming (IOI13_dreaming) C++17
65 / 100
60 ms 13724 KB
#include "dreaming.h"
#include <bits/stdc++.h>
using namespace std ;
#define pii pair <int , int>
#define ff first 
#define ss second

const int inf = 1e9 ;
const int N = 1e5 + 5 ;

template <class T>
bool chmax( T& x , const T& y ){
  bool f = 0 ;
  if ( x < y ) x = y , f = 1 ;
  return f ;
}
template <class T>
bool chmin( T &x , const T &y ){
  bool f = 0 ;
  if ( x > y ) x = y , f = 1 ;
  return f ;
}

bool vis[N] ;
int d[N] , f[N] , sc[N] ;
int mx , m , ind , r ;
pii ans[N] ;
vector <pii> g[N] ;

void dfs ( int v , int s , int& m ){
	vis[v] = 1 ; d[v] = s ;
	if ( mx <= d[v] ){
		m = v ; mx = d[v] ;
	}
	for ( auto to : g[v] ) if ( !vis[to.ff] ) dfs(to.ff,s+to.ss,m) ;
}
void fir ( int v , int d , int& m ){
	vis[v] = 0 ; f[v] = d ;
	if ( chmax ( mx , f[v] ) ) m = v ;
	for ( auto to : g[v] ) if ( vis[to.ff] ) fir(to.ff,d+to.ss,m) ;
}
void sec ( int v , int d , int& m ){
	vis[v] = 1 ; sc[v] = d ;
	if ( max( f[v] , sc[v] ) < mx ){
		mx = max ( f[v] , sc[v] ) ; m = v ;
	}
	for ( auto to : g[v] ) if ( !vis[to.ff] ) sec(to.ff,d+to.ss,m) ;
}

int travelTime(int n, int m, int l, int a[], int b[], int c[]) {
    for ( int i = 0 ; i < m ; i ++ ){
		g[a[i]].push_back({b[i],c[i]}) ;
		g[b[i]].push_back({a[i],c[i]}) ;
	}
	if ( m == n-2 ){
		for ( int i = 1 ; i <= n ; i ++ ){
			if ( !vis[i] ){
				mx = 0 ;
				dfs(i,0,m) ;
				mx = 0 ;
				fir(m,0,m) ;
				chmax ( r , f[m] ) ; 
				mx = inf ;
				sec(m,0,m) ;
				ans[ind].ff = f[m] ;
				ans[ind].ss = sc[m] ;
				ind ++ ;
			}
		}
		return max (r,l + max(ans[0].ff,ans[0].ss) + max( ans[1].ff , ans[1].ss )) ;
	}
	if ( n == 1 ) return 0 ;
	if ( n == 2 ){
		if ( m == 1 ) return 0 ;
		return l ;
	}
	vector <int> vec ;
	for ( int i = 0 ; i < m ; i ++ ) vec.push_back(c[i]) ;
	for ( int i = 0 ; i < 5 ; i ++ ) vec.push_back(0) ;
	sort ( vec.rbegin() , vec.rend() ) ;
	return max ( vec[0]+vec[1]+l , vec[1]+vec[2]+2*l ) ;
	
}
/*
signed main(){
	int n , m , l , a[N] , b[N] , t[N] ;
	cin >> n >> m >> l ;
	for ( int i = 0 ; i < m ; i ++ ) cin >> a[i] >> b[i] >> t[i] ;
	cout << travelTime( n , m , l , a , b , t ) ;
}

*/
# Verdict Execution time Memory Grader output
1 Correct 43 ms 13140 KB Output is correct
2 Correct 34 ms 13148 KB Output is correct
3 Correct 24 ms 10320 KB Output is correct
4 Correct 6 ms 5724 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 9 ms 6412 KB Output is correct
7 Correct 1 ms 4532 KB Output is correct
8 Correct 17 ms 7516 KB Output is correct
9 Correct 24 ms 8976 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 30 ms 10000 KB Output is correct
12 Correct 33 ms 11356 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4640 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4536 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 13140 KB Output is correct
2 Correct 34 ms 13148 KB Output is correct
3 Correct 24 ms 10320 KB Output is correct
4 Correct 6 ms 5724 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 9 ms 6412 KB Output is correct
7 Correct 1 ms 4532 KB Output is correct
8 Correct 17 ms 7516 KB Output is correct
9 Correct 24 ms 8976 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 30 ms 10000 KB Output is correct
12 Correct 33 ms 11356 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4640 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4536 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 30 ms 12888 KB Output is correct
40 Correct 41 ms 13140 KB Output is correct
41 Correct 22 ms 10508 KB Output is correct
42 Correct 6 ms 5832 KB Output is correct
43 Correct 1 ms 4452 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4544 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4532 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 40 ms 10324 KB Output is correct
58 Correct 41 ms 10404 KB Output is correct
59 Correct 41 ms 10060 KB Output is correct
60 Correct 41 ms 10064 KB Output is correct
61 Correct 40 ms 10064 KB Output is correct
62 Correct 39 ms 9956 KB Output is correct
63 Correct 36 ms 9820 KB Output is correct
64 Correct 36 ms 9764 KB Output is correct
65 Correct 42 ms 10348 KB Output is correct
66 Correct 39 ms 10068 KB Output is correct
67 Correct 40 ms 10064 KB Output is correct
68 Correct 41 ms 9808 KB Output is correct
69 Correct 41 ms 10200 KB Output is correct
70 Correct 42 ms 10088 KB Output is correct
71 Correct 1 ms 4440 KB Output is correct
72 Correct 2 ms 4700 KB Output is correct
73 Correct 2 ms 4700 KB Output is correct
74 Correct 2 ms 4700 KB Output is correct
75 Correct 2 ms 4700 KB Output is correct
76 Correct 2 ms 4700 KB Output is correct
77 Correct 2 ms 4532 KB Output is correct
78 Correct 2 ms 4700 KB Output is correct
79 Correct 2 ms 4700 KB Output is correct
80 Correct 41 ms 10324 KB Output is correct
81 Correct 60 ms 10560 KB Output is correct
82 Correct 37 ms 10016 KB Output is correct
83 Correct 38 ms 9812 KB Output is correct
84 Correct 2 ms 4696 KB Output is correct
85 Correct 2 ms 4444 KB Output is correct
86 Correct 2 ms 4700 KB Output is correct
87 Correct 2 ms 4700 KB Output is correct
88 Correct 2 ms 4696 KB Output is correct
89 Correct 2 ms 4696 KB Output is correct
90 Correct 2 ms 4952 KB Output is correct
91 Correct 2 ms 4700 KB Output is correct
92 Correct 2 ms 4700 KB Output is correct
93 Correct 2 ms 4700 KB Output is correct
94 Correct 1 ms 4444 KB Output is correct
95 Correct 1 ms 4444 KB Output is correct
96 Correct 1 ms 4444 KB Output is correct
97 Correct 1 ms 4444 KB Output is correct
98 Correct 1 ms 4696 KB Output is correct
99 Correct 1 ms 4444 KB Output is correct
100 Correct 1 ms 4444 KB Output is correct
101 Correct 1 ms 4444 KB Output is correct
102 Correct 1 ms 4444 KB Output is correct
103 Correct 1 ms 4444 KB Output is correct
104 Correct 4 ms 5212 KB Output is correct
105 Correct 9 ms 6488 KB Output is correct
106 Correct 1 ms 4444 KB Output is correct
107 Correct 17 ms 7392 KB Output is correct
108 Correct 23 ms 8688 KB Output is correct
109 Correct 1 ms 4444 KB Output is correct
110 Correct 30 ms 10172 KB Output is correct
111 Correct 33 ms 11356 KB Output is correct
112 Correct 1 ms 4444 KB Output is correct
113 Correct 46 ms 13724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 6792 KB Output is correct
2 Correct 11 ms 6960 KB Output is correct
3 Correct 11 ms 6748 KB Output is correct
4 Correct 14 ms 6748 KB Output is correct
5 Correct 11 ms 6748 KB Output is correct
6 Correct 11 ms 7164 KB Output is correct
7 Correct 11 ms 6748 KB Output is correct
8 Correct 10 ms 6644 KB Output is correct
9 Correct 11 ms 6748 KB Output is correct
10 Correct 11 ms 7256 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4440 KB Output is correct
13 Correct 2 ms 4444 KB Output is correct
14 Correct 1 ms 4696 KB Output is correct
15 Correct 1 ms 4440 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4440 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4440 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4640 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4536 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Incorrect 1 ms 4556 KB Output isn't correct
27 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 43 ms 13140 KB Output is correct
2 Correct 34 ms 13148 KB Output is correct
3 Correct 24 ms 10320 KB Output is correct
4 Correct 6 ms 5724 KB Output is correct
5 Correct 4 ms 5212 KB Output is correct
6 Correct 9 ms 6412 KB Output is correct
7 Correct 1 ms 4532 KB Output is correct
8 Correct 17 ms 7516 KB Output is correct
9 Correct 24 ms 8976 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 30 ms 10000 KB Output is correct
12 Correct 33 ms 11356 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 2 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 1 ms 4444 KB Output is correct
30 Correct 1 ms 4444 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4640 KB Output is correct
36 Correct 1 ms 4444 KB Output is correct
37 Correct 1 ms 4536 KB Output is correct
38 Correct 1 ms 4444 KB Output is correct
39 Correct 30 ms 12888 KB Output is correct
40 Correct 41 ms 13140 KB Output is correct
41 Correct 22 ms 10508 KB Output is correct
42 Correct 6 ms 5832 KB Output is correct
43 Correct 1 ms 4452 KB Output is correct
44 Correct 1 ms 4444 KB Output is correct
45 Correct 1 ms 4444 KB Output is correct
46 Correct 1 ms 4444 KB Output is correct
47 Correct 1 ms 4544 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 1 ms 4444 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4444 KB Output is correct
52 Correct 1 ms 4532 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 1 ms 4444 KB Output is correct
56 Correct 1 ms 4444 KB Output is correct
57 Correct 40 ms 10324 KB Output is correct
58 Correct 41 ms 10404 KB Output is correct
59 Correct 41 ms 10060 KB Output is correct
60 Correct 41 ms 10064 KB Output is correct
61 Correct 40 ms 10064 KB Output is correct
62 Correct 39 ms 9956 KB Output is correct
63 Correct 36 ms 9820 KB Output is correct
64 Correct 36 ms 9764 KB Output is correct
65 Correct 42 ms 10348 KB Output is correct
66 Correct 39 ms 10068 KB Output is correct
67 Correct 40 ms 10064 KB Output is correct
68 Correct 41 ms 9808 KB Output is correct
69 Correct 41 ms 10200 KB Output is correct
70 Correct 42 ms 10088 KB Output is correct
71 Correct 1 ms 4440 KB Output is correct
72 Correct 2 ms 4700 KB Output is correct
73 Correct 2 ms 4700 KB Output is correct
74 Correct 2 ms 4700 KB Output is correct
75 Correct 2 ms 4700 KB Output is correct
76 Correct 2 ms 4700 KB Output is correct
77 Correct 2 ms 4532 KB Output is correct
78 Correct 2 ms 4700 KB Output is correct
79 Correct 2 ms 4700 KB Output is correct
80 Correct 41 ms 10324 KB Output is correct
81 Correct 60 ms 10560 KB Output is correct
82 Correct 37 ms 10016 KB Output is correct
83 Correct 38 ms 9812 KB Output is correct
84 Correct 2 ms 4696 KB Output is correct
85 Correct 2 ms 4444 KB Output is correct
86 Correct 2 ms 4700 KB Output is correct
87 Correct 2 ms 4700 KB Output is correct
88 Correct 2 ms 4696 KB Output is correct
89 Correct 2 ms 4696 KB Output is correct
90 Correct 2 ms 4952 KB Output is correct
91 Correct 2 ms 4700 KB Output is correct
92 Correct 2 ms 4700 KB Output is correct
93 Correct 2 ms 4700 KB Output is correct
94 Correct 1 ms 4444 KB Output is correct
95 Correct 1 ms 4444 KB Output is correct
96 Correct 1 ms 4444 KB Output is correct
97 Correct 1 ms 4444 KB Output is correct
98 Correct 1 ms 4696 KB Output is correct
99 Correct 1 ms 4444 KB Output is correct
100 Correct 1 ms 4444 KB Output is correct
101 Correct 1 ms 4444 KB Output is correct
102 Correct 1 ms 4444 KB Output is correct
103 Correct 1 ms 4444 KB Output is correct
104 Correct 4 ms 5212 KB Output is correct
105 Correct 9 ms 6488 KB Output is correct
106 Correct 1 ms 4444 KB Output is correct
107 Correct 17 ms 7392 KB Output is correct
108 Correct 23 ms 8688 KB Output is correct
109 Correct 1 ms 4444 KB Output is correct
110 Correct 30 ms 10172 KB Output is correct
111 Correct 33 ms 11356 KB Output is correct
112 Correct 1 ms 4444 KB Output is correct
113 Correct 46 ms 13724 KB Output is correct
114 Correct 11 ms 6792 KB Output is correct
115 Correct 11 ms 6960 KB Output is correct
116 Correct 11 ms 6748 KB Output is correct
117 Correct 14 ms 6748 KB Output is correct
118 Correct 11 ms 6748 KB Output is correct
119 Correct 11 ms 7164 KB Output is correct
120 Correct 11 ms 6748 KB Output is correct
121 Correct 10 ms 6644 KB Output is correct
122 Correct 11 ms 6748 KB Output is correct
123 Correct 11 ms 7256 KB Output is correct
124 Correct 1 ms 4444 KB Output is correct
125 Correct 1 ms 4440 KB Output is correct
126 Correct 2 ms 4444 KB Output is correct
127 Correct 1 ms 4696 KB Output is correct
128 Correct 1 ms 4440 KB Output is correct
129 Correct 1 ms 4440 KB Output is correct
130 Correct 1 ms 4444 KB Output is correct
131 Correct 1 ms 4444 KB Output is correct
132 Correct 1 ms 4440 KB Output is correct
133 Correct 1 ms 4444 KB Output is correct
134 Correct 1 ms 4444 KB Output is correct
135 Correct 1 ms 4444 KB Output is correct
136 Correct 1 ms 4444 KB Output is correct
137 Incorrect 1 ms 4556 KB Output isn't correct
138 Halted 0 ms 0 KB -