Submission #897401

# Submission time Handle Problem Language Result Execution time Memory
897401 2024-01-03T03:58:01 Z Faisal_Saqib Dreaming (IOI13_dreaming) C++17
59 / 100
1000 ms 20004 KB
#include "dreaming.h"
#include <iostream>
#include <vector>
#include <set>
using namespace std; 
const long long N=1e5+200;
vector<pair<long long,long long>> ma[N];
bool vis[N];
bool tp=0;
long long dp_down[N][2];
long long dp_up[N];
long long mxx[N];
long long n,m,l;
void dfs_down(long long x,long long p=-1)
{
	vis[x]=1;
	dp_down[x][0]=dp_down[x][1]=0;
	for(auto [w,y]:ma[x])
	{
		if(y!=p)
		{
			dfs_down(y,x);
			long long cur=dp_down[y][0]+w;
			if(dp_down[x][0]<cur)
			{
				dp_down[x][1]=dp_down[x][0];
				dp_down[x][0]=cur;
			}
			else if(dp_down[x][1]<cur)
			{
				dp_down[x][1]=cur;
			}
		}
	}
}
long long vertex=-1;
long long dist=1e18;
long long cp=-1;
void fill()
{
	for(int i=0;i<n;i++)
		dp_up[i]=0;
}
void dfs_up(long long x,long long p=-1)
{
	mxx[x]=max(dp_up[x],dp_down[x][0]);
	cp=max(cp,mxx[x]);
	// if(tp)
	// {
	// 	cout<<"For "<<x<<' '<<mxx[x]<<endl;
	// }
	if(mxx[x]<dist)
	{
		dist=mxx[x];
		vertex=x;
	}
	for(auto [w,y]:ma[x])
	{
		if(y!=p)
		{
			dp_up[y]=dp_up[x]+w;
			if(dp_down[x][0]==(dp_down[y][0]+w))
				dp_up[y]=max(dp_up[y],dp_down[x][1]+w);
			else
				dp_up[y]=max(dp_up[y],dp_down[x][0]+w);
			dfs_up(y,x);
		}
	}
}
int travelTime(int N, int M, int L, int a[], int b[], int t[])
{
	n=N;
	m=M;
	l=L;
	for(int i=0;i<m;i++)
	{
		ma[a[i]].push_back({t[i],b[i]});
		ma[b[i]].push_back({t[i],a[i]});
	}
	set<pair<long long,long long>> stp;
	for(int i=0;i<n;i++)
	{
		if(!vis[i]){
			vertex=-1;
			dist=1e18;
			dfs_down(i);
			dfs_up(i);
			stp.insert({dist,vertex});
		}
	}
	while(stp.size()>1)
	{
		auto lt=*(--end(stp));
		stp.erase((--end(stp)));
		auto ft=*(begin(stp));
		stp.erase((begin(stp)));
		// Merge them 
		ma[lt.second].push_back({l,ft.second});
		ma[ft.second].push_back({l,lt.second});
		vertex=-1;
		dist=1e18;
		dfs_down(lt.second);
		fill();
		dfs_up(lt.second);
		stp.insert({dist,vertex});
	}
	cp=-1;
	tp=1;
	dfs_down(0);
	fill();
	dfs_up(0);
	// cout<<"adj\n";
	// for(int i=0;i<n;i++)
	// {
	// 	cout<<"For "<<i<<' ';
	// 	for(auto [j,p]:ma[i]){
	// 		cout<<p<<' ';
	// 	}
	// 	cout<<endl;
	// 	cout<<"a\n";
	// }
	return cp;
}
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15188 KB Output is correct
2 Correct 48 ms 15228 KB Output is correct
3 Correct 30 ms 13916 KB Output is correct
4 Correct 6 ms 8028 KB Output is correct
5 Correct 6 ms 7772 KB Output is correct
6 Correct 12 ms 8992 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 22 ms 10588 KB Output is correct
9 Correct 29 ms 12864 KB Output is correct
10 Correct 1 ms 7000 KB Output is correct
11 Correct 41 ms 13404 KB Output is correct
12 Correct 57 ms 14420 KB Output is correct
13 Correct 2 ms 7000 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7004 KB Output is correct
2 Correct 1 ms 7004 KB Output is correct
3 Correct 1 ms 7004 KB Output is correct
4 Correct 1 ms 7004 KB Output is correct
5 Correct 1 ms 7004 KB Output is correct
6 Correct 1 ms 7004 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 1 ms 7004 KB Output is correct
9 Correct 2 ms 7000 KB Output is correct
10 Correct 1 ms 7004 KB Output is correct
11 Correct 1 ms 7004 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 1 ms 7004 KB Output is correct
14 Correct 1 ms 7004 KB Output is correct
15 Correct 1 ms 7004 KB Output is correct
16 Correct 1 ms 7004 KB Output is correct
17 Correct 1 ms 7004 KB Output is correct
18 Correct 1 ms 7004 KB Output is correct
19 Correct 1 ms 7004 KB Output is correct
20 Correct 1 ms 7004 KB Output is correct
21 Correct 2 ms 7004 KB Output is correct
22 Correct 1 ms 7004 KB Output is correct
23 Correct 1 ms 7004 KB Output is correct
24 Correct 1 ms 7000 KB Output is correct
25 Correct 1 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15188 KB Output is correct
2 Correct 48 ms 15228 KB Output is correct
3 Correct 30 ms 13916 KB Output is correct
4 Correct 6 ms 8028 KB Output is correct
5 Correct 6 ms 7772 KB Output is correct
6 Correct 12 ms 8992 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 22 ms 10588 KB Output is correct
9 Correct 29 ms 12864 KB Output is correct
10 Correct 1 ms 7000 KB Output is correct
11 Correct 41 ms 13404 KB Output is correct
12 Correct 57 ms 14420 KB Output is correct
13 Correct 2 ms 7000 KB Output is correct
14 Correct 1 ms 7004 KB Output is correct
15 Correct 1 ms 7004 KB Output is correct
16 Correct 1 ms 7004 KB Output is correct
17 Correct 1 ms 7004 KB Output is correct
18 Correct 1 ms 7004 KB Output is correct
19 Correct 1 ms 7004 KB Output is correct
20 Correct 1 ms 7004 KB Output is correct
21 Correct 1 ms 7004 KB Output is correct
22 Correct 2 ms 7000 KB Output is correct
23 Correct 1 ms 7004 KB Output is correct
24 Correct 1 ms 7004 KB Output is correct
25 Correct 2 ms 7004 KB Output is correct
26 Correct 1 ms 7004 KB Output is correct
27 Correct 1 ms 7004 KB Output is correct
28 Correct 1 ms 7004 KB Output is correct
29 Correct 1 ms 7004 KB Output is correct
30 Correct 1 ms 7004 KB Output is correct
31 Correct 1 ms 7004 KB Output is correct
32 Correct 1 ms 7004 KB Output is correct
33 Correct 1 ms 7004 KB Output is correct
34 Correct 2 ms 7004 KB Output is correct
35 Correct 1 ms 7004 KB Output is correct
36 Correct 1 ms 7004 KB Output is correct
37 Correct 1 ms 7000 KB Output is correct
38 Correct 1 ms 7004 KB Output is correct
39 Correct 51 ms 15384 KB Output is correct
40 Correct 39 ms 14932 KB Output is correct
41 Correct 28 ms 13848 KB Output is correct
42 Correct 8 ms 8084 KB Output is correct
43 Correct 2 ms 7000 KB Output is correct
44 Correct 1 ms 7004 KB Output is correct
45 Correct 1 ms 7004 KB Output is correct
46 Correct 1 ms 7028 KB Output is correct
47 Correct 2 ms 7004 KB Output is correct
48 Correct 1 ms 7004 KB Output is correct
49 Correct 1 ms 7004 KB Output is correct
50 Correct 1 ms 7004 KB Output is correct
51 Correct 1 ms 7004 KB Output is correct
52 Correct 2 ms 7004 KB Output is correct
53 Correct 1 ms 7004 KB Output is correct
54 Correct 1 ms 7004 KB Output is correct
55 Correct 1 ms 7004 KB Output is correct
56 Correct 1 ms 7004 KB Output is correct
57 Correct 52 ms 13036 KB Output is correct
58 Correct 51 ms 12880 KB Output is correct
59 Correct 57 ms 12628 KB Output is correct
60 Correct 60 ms 12632 KB Output is correct
61 Correct 65 ms 12372 KB Output is correct
62 Correct 50 ms 12608 KB Output is correct
63 Correct 48 ms 12124 KB Output is correct
64 Correct 46 ms 12120 KB Output is correct
65 Correct 48 ms 12120 KB Output is correct
66 Correct 51 ms 12116 KB Output is correct
67 Correct 55 ms 12624 KB Output is correct
68 Correct 61 ms 12692 KB Output is correct
69 Correct 58 ms 12816 KB Output is correct
70 Correct 53 ms 12716 KB Output is correct
71 Correct 1 ms 7000 KB Output is correct
72 Correct 2 ms 7000 KB Output is correct
73 Correct 2 ms 7004 KB Output is correct
74 Correct 2 ms 7004 KB Output is correct
75 Correct 2 ms 7100 KB Output is correct
76 Correct 2 ms 7004 KB Output is correct
77 Correct 2 ms 7004 KB Output is correct
78 Correct 3 ms 7004 KB Output is correct
79 Correct 2 ms 7204 KB Output is correct
80 Correct 52 ms 12808 KB Output is correct
81 Correct 59 ms 12632 KB Output is correct
82 Correct 54 ms 12604 KB Output is correct
83 Correct 100 ms 12608 KB Output is correct
84 Correct 2 ms 7000 KB Output is correct
85 Correct 2 ms 7256 KB Output is correct
86 Correct 2 ms 7004 KB Output is correct
87 Correct 2 ms 7004 KB Output is correct
88 Correct 2 ms 7004 KB Output is correct
89 Correct 2 ms 7004 KB Output is correct
90 Correct 2 ms 7004 KB Output is correct
91 Correct 2 ms 7004 KB Output is correct
92 Correct 2 ms 7004 KB Output is correct
93 Correct 2 ms 7004 KB Output is correct
94 Correct 1 ms 7004 KB Output is correct
95 Correct 1 ms 7004 KB Output is correct
96 Correct 1 ms 7004 KB Output is correct
97 Correct 1 ms 7004 KB Output is correct
98 Correct 2 ms 7204 KB Output is correct
99 Correct 1 ms 7000 KB Output is correct
100 Correct 1 ms 7004 KB Output is correct
101 Correct 1 ms 7004 KB Output is correct
102 Correct 1 ms 7004 KB Output is correct
103 Correct 1 ms 7004 KB Output is correct
104 Correct 6 ms 7772 KB Output is correct
105 Correct 11 ms 9072 KB Output is correct
106 Correct 1 ms 7020 KB Output is correct
107 Correct 21 ms 10588 KB Output is correct
108 Correct 29 ms 12636 KB Output is correct
109 Correct 2 ms 7004 KB Output is correct
110 Correct 39 ms 13404 KB Output is correct
111 Correct 61 ms 14592 KB Output is correct
112 Correct 2 ms 7004 KB Output is correct
113 Correct 80 ms 20004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 13280 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 7004 KB Output is correct
2 Correct 1 ms 7004 KB Output is correct
3 Correct 1 ms 7004 KB Output is correct
4 Correct 1 ms 7004 KB Output is correct
5 Correct 1 ms 7004 KB Output is correct
6 Correct 1 ms 7004 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 1 ms 7004 KB Output is correct
9 Correct 2 ms 7000 KB Output is correct
10 Correct 1 ms 7004 KB Output is correct
11 Correct 1 ms 7004 KB Output is correct
12 Correct 2 ms 7004 KB Output is correct
13 Correct 1 ms 7004 KB Output is correct
14 Correct 1 ms 7004 KB Output is correct
15 Correct 1 ms 7004 KB Output is correct
16 Correct 1 ms 7004 KB Output is correct
17 Correct 1 ms 7004 KB Output is correct
18 Correct 1 ms 7004 KB Output is correct
19 Correct 1 ms 7004 KB Output is correct
20 Correct 1 ms 7004 KB Output is correct
21 Correct 2 ms 7004 KB Output is correct
22 Correct 1 ms 7004 KB Output is correct
23 Correct 1 ms 7004 KB Output is correct
24 Correct 1 ms 7000 KB Output is correct
25 Correct 1 ms 7004 KB Output is correct
26 Correct 2 ms 7000 KB Output is correct
27 Correct 7 ms 7000 KB Output is correct
28 Correct 13 ms 7000 KB Output is correct
29 Correct 2 ms 7004 KB Output is correct
30 Correct 5 ms 7004 KB Output is correct
31 Correct 14 ms 7004 KB Output is correct
32 Correct 2 ms 7004 KB Output is correct
33 Correct 5 ms 7128 KB Output is correct
34 Correct 9 ms 7052 KB Output is correct
35 Correct 1 ms 7004 KB Output is correct
36 Correct 1 ms 7004 KB Output is correct
37 Correct 1 ms 7004 KB Output is correct
38 Correct 1 ms 7004 KB Output is correct
39 Correct 1 ms 7004 KB Output is correct
40 Correct 1 ms 7004 KB Output is correct
41 Correct 1 ms 7004 KB Output is correct
42 Correct 1 ms 7004 KB Output is correct
43 Correct 1 ms 7004 KB Output is correct
44 Correct 1 ms 7004 KB Output is correct
45 Correct 1 ms 7004 KB Output is correct
46 Correct 1 ms 7004 KB Output is correct
47 Correct 1 ms 7004 KB Output is correct
48 Correct 1 ms 7004 KB Output is correct
49 Correct 1 ms 7004 KB Output is correct
50 Correct 2 ms 6844 KB Output is correct
51 Correct 1 ms 7004 KB Output is correct
52 Correct 1 ms 7004 KB Output is correct
53 Correct 1 ms 7004 KB Output is correct
54 Correct 2 ms 7260 KB Output is correct
55 Correct 3 ms 7284 KB Output is correct
56 Correct 21 ms 7260 KB Output is correct
57 Correct 36 ms 7260 KB Output is correct
58 Correct 2 ms 7000 KB Output is correct
59 Correct 3 ms 7004 KB Output is correct
60 Correct 26 ms 7272 KB Output is correct
61 Correct 33 ms 7260 KB Output is correct
62 Correct 2 ms 7000 KB Output is correct
63 Correct 3 ms 7028 KB Output is correct
64 Correct 47 ms 7260 KB Output is correct
65 Correct 19 ms 7000 KB Output is correct
66 Correct 2 ms 7252 KB Output is correct
67 Correct 2 ms 7004 KB Output is correct
68 Correct 21 ms 7236 KB Output is correct
69 Correct 16 ms 7000 KB Output is correct
70 Correct 29 ms 7260 KB Output is correct
71 Correct 29 ms 7260 KB Output is correct
72 Correct 2 ms 7004 KB Output is correct
73 Correct 2 ms 7004 KB Output is correct
74 Correct 7 ms 7004 KB Output is correct
75 Correct 6 ms 7004 KB Output is correct
76 Correct 2 ms 7096 KB Output is correct
77 Correct 2 ms 7004 KB Output is correct
78 Correct 29 ms 7284 KB Output is correct
79 Correct 29 ms 7260 KB Output is correct
80 Correct 46 ms 7260 KB Output is correct
81 Correct 50 ms 7260 KB Output is correct
82 Correct 8 ms 7004 KB Output is correct
83 Correct 8 ms 7000 KB Output is correct
84 Correct 50 ms 7252 KB Output is correct
85 Correct 52 ms 7260 KB Output is correct
86 Correct 43 ms 7004 KB Output is correct
87 Correct 23 ms 7000 KB Output is correct
88 Correct 19 ms 7260 KB Output is correct
89 Correct 22 ms 7128 KB Output is correct
90 Correct 27 ms 7256 KB Output is correct
91 Correct 29 ms 7260 KB Output is correct
92 Correct 2 ms 7000 KB Output is correct
93 Correct 2 ms 7004 KB Output is correct
94 Correct 2 ms 7164 KB Output is correct
95 Correct 2 ms 7096 KB Output is correct
96 Correct 3 ms 7176 KB Output is correct
97 Correct 2 ms 7004 KB Output is correct
98 Correct 2 ms 7004 KB Output is correct
99 Correct 2 ms 7004 KB Output is correct
100 Correct 2 ms 7004 KB Output is correct
101 Correct 2 ms 7004 KB Output is correct
102 Correct 1 ms 7004 KB Output is correct
103 Correct 1 ms 7000 KB Output is correct
104 Correct 1 ms 7004 KB Output is correct
105 Correct 1 ms 7004 KB Output is correct
106 Correct 1 ms 7004 KB Output is correct
107 Correct 1 ms 7004 KB Output is correct
108 Correct 1 ms 7004 KB Output is correct
109 Correct 1 ms 7024 KB Output is correct
110 Correct 1 ms 7004 KB Output is correct
111 Correct 1 ms 7004 KB Output is correct
112 Correct 1 ms 7004 KB Output is correct
113 Correct 1 ms 7004 KB Output is correct
114 Correct 1 ms 7004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 15188 KB Output is correct
2 Correct 48 ms 15228 KB Output is correct
3 Correct 30 ms 13916 KB Output is correct
4 Correct 6 ms 8028 KB Output is correct
5 Correct 6 ms 7772 KB Output is correct
6 Correct 12 ms 8992 KB Output is correct
7 Correct 1 ms 7004 KB Output is correct
8 Correct 22 ms 10588 KB Output is correct
9 Correct 29 ms 12864 KB Output is correct
10 Correct 1 ms 7000 KB Output is correct
11 Correct 41 ms 13404 KB Output is correct
12 Correct 57 ms 14420 KB Output is correct
13 Correct 2 ms 7000 KB Output is correct
14 Correct 1 ms 7004 KB Output is correct
15 Correct 1 ms 7004 KB Output is correct
16 Correct 1 ms 7004 KB Output is correct
17 Correct 1 ms 7004 KB Output is correct
18 Correct 1 ms 7004 KB Output is correct
19 Correct 1 ms 7004 KB Output is correct
20 Correct 1 ms 7004 KB Output is correct
21 Correct 1 ms 7004 KB Output is correct
22 Correct 2 ms 7000 KB Output is correct
23 Correct 1 ms 7004 KB Output is correct
24 Correct 1 ms 7004 KB Output is correct
25 Correct 2 ms 7004 KB Output is correct
26 Correct 1 ms 7004 KB Output is correct
27 Correct 1 ms 7004 KB Output is correct
28 Correct 1 ms 7004 KB Output is correct
29 Correct 1 ms 7004 KB Output is correct
30 Correct 1 ms 7004 KB Output is correct
31 Correct 1 ms 7004 KB Output is correct
32 Correct 1 ms 7004 KB Output is correct
33 Correct 1 ms 7004 KB Output is correct
34 Correct 2 ms 7004 KB Output is correct
35 Correct 1 ms 7004 KB Output is correct
36 Correct 1 ms 7004 KB Output is correct
37 Correct 1 ms 7000 KB Output is correct
38 Correct 1 ms 7004 KB Output is correct
39 Correct 51 ms 15384 KB Output is correct
40 Correct 39 ms 14932 KB Output is correct
41 Correct 28 ms 13848 KB Output is correct
42 Correct 8 ms 8084 KB Output is correct
43 Correct 2 ms 7000 KB Output is correct
44 Correct 1 ms 7004 KB Output is correct
45 Correct 1 ms 7004 KB Output is correct
46 Correct 1 ms 7028 KB Output is correct
47 Correct 2 ms 7004 KB Output is correct
48 Correct 1 ms 7004 KB Output is correct
49 Correct 1 ms 7004 KB Output is correct
50 Correct 1 ms 7004 KB Output is correct
51 Correct 1 ms 7004 KB Output is correct
52 Correct 2 ms 7004 KB Output is correct
53 Correct 1 ms 7004 KB Output is correct
54 Correct 1 ms 7004 KB Output is correct
55 Correct 1 ms 7004 KB Output is correct
56 Correct 1 ms 7004 KB Output is correct
57 Correct 52 ms 13036 KB Output is correct
58 Correct 51 ms 12880 KB Output is correct
59 Correct 57 ms 12628 KB Output is correct
60 Correct 60 ms 12632 KB Output is correct
61 Correct 65 ms 12372 KB Output is correct
62 Correct 50 ms 12608 KB Output is correct
63 Correct 48 ms 12124 KB Output is correct
64 Correct 46 ms 12120 KB Output is correct
65 Correct 48 ms 12120 KB Output is correct
66 Correct 51 ms 12116 KB Output is correct
67 Correct 55 ms 12624 KB Output is correct
68 Correct 61 ms 12692 KB Output is correct
69 Correct 58 ms 12816 KB Output is correct
70 Correct 53 ms 12716 KB Output is correct
71 Correct 1 ms 7000 KB Output is correct
72 Correct 2 ms 7000 KB Output is correct
73 Correct 2 ms 7004 KB Output is correct
74 Correct 2 ms 7004 KB Output is correct
75 Correct 2 ms 7100 KB Output is correct
76 Correct 2 ms 7004 KB Output is correct
77 Correct 2 ms 7004 KB Output is correct
78 Correct 3 ms 7004 KB Output is correct
79 Correct 2 ms 7204 KB Output is correct
80 Correct 52 ms 12808 KB Output is correct
81 Correct 59 ms 12632 KB Output is correct
82 Correct 54 ms 12604 KB Output is correct
83 Correct 100 ms 12608 KB Output is correct
84 Correct 2 ms 7000 KB Output is correct
85 Correct 2 ms 7256 KB Output is correct
86 Correct 2 ms 7004 KB Output is correct
87 Correct 2 ms 7004 KB Output is correct
88 Correct 2 ms 7004 KB Output is correct
89 Correct 2 ms 7004 KB Output is correct
90 Correct 2 ms 7004 KB Output is correct
91 Correct 2 ms 7004 KB Output is correct
92 Correct 2 ms 7004 KB Output is correct
93 Correct 2 ms 7004 KB Output is correct
94 Correct 1 ms 7004 KB Output is correct
95 Correct 1 ms 7004 KB Output is correct
96 Correct 1 ms 7004 KB Output is correct
97 Correct 1 ms 7004 KB Output is correct
98 Correct 2 ms 7204 KB Output is correct
99 Correct 1 ms 7000 KB Output is correct
100 Correct 1 ms 7004 KB Output is correct
101 Correct 1 ms 7004 KB Output is correct
102 Correct 1 ms 7004 KB Output is correct
103 Correct 1 ms 7004 KB Output is correct
104 Correct 6 ms 7772 KB Output is correct
105 Correct 11 ms 9072 KB Output is correct
106 Correct 1 ms 7020 KB Output is correct
107 Correct 21 ms 10588 KB Output is correct
108 Correct 29 ms 12636 KB Output is correct
109 Correct 2 ms 7004 KB Output is correct
110 Correct 39 ms 13404 KB Output is correct
111 Correct 61 ms 14592 KB Output is correct
112 Correct 2 ms 7004 KB Output is correct
113 Correct 80 ms 20004 KB Output is correct
114 Execution timed out 1070 ms 13280 KB Time limit exceeded
115 Halted 0 ms 0 KB -