Submission #224777

# Submission time Handle Problem Language Result Execution time Memory
224777 2020-04-18T18:55:30 Z nafis_shifat Dreaming (IOI13_dreaming) C++14
47 / 100
230 ms 24028 KB
#include "dreaming.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define ll long long
using namespace std;
const int mxn=1e5+6;

vector<int> adj[mxn];
vector<int> cost[mxn];

int m1[mxn]={};
int m2[mxn]={};
int u1[mxn];

int ans=0;
int vis[mxn]={};
void dfs(int cur,int prev)
{
	vis[cur]=1;
	for(int i=0;i<adj[cur].size();i++)
	{
		int v=adj[cur][i];
		int c=cost[cur][i];
		if(v==prev)continue;

		dfs(v,cur);
		int k=m1[v]+c;

		if(k>m1[cur])
		{
			m2[cur]=m1[cur];
			m1[cur]=k;
			u1[cur]=v;
		}
		else if(k>m2[cur])
			m2[cur]=k;
		
		

	}
}
vector<int> v;
void calc(int cur,int prev,int cst)
{

	v.push_back(max(cst,m1[cur]));
	ans=max(ans,cst+m1[cur]);

	for(int i=0;i<adj[cur].size();i++)
	{
		int v=adj[cur][i];
		int c=cost[cur][i];

		if(v==prev)continue;

		int tmp=cst+c;

		if(v==u1[cur])tmp=max(tmp,m2[cur]+c);
		else tmp=max(tmp,m1[cur]+c);
		calc(v,cur,tmp);
	}
}
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]);
		adj[B[i]].push_back(A[i]);

		cost[A[i]].push_back(T[i]);
		cost[B[i]].push_back(T[i]);
	}


	vector<int> fn;

	for(int i=0;i<N;i++)
	{
		if(vis[i])continue;
		dfs(i,-1);

		calc(i,-1,0);

		sort(v.begin(),v.end());
		fn.push_back(v[0]);

		v.clear();
		


	}
	sort(fn.begin(),fn.end(),greater<int>());
   
	if(fn.size()>1)
	{
		ans=max(ans,fn[0]+fn[1]+L);
	}
	if(fn.size()>2)
	{
		ans=max(ans,fn[2]+fn[3]+2*L);
	}

	return ans;

}

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:20:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<adj[cur].size();i++)
              ~^~~~~~~~~~~~~~~~
dreaming.cpp: In function 'void calc(int, int, int)':
dreaming.cpp:49:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<adj[cur].size();i++)
              ~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 97 ms 19060 KB Output is correct
2 Correct 101 ms 18804 KB Output is correct
3 Correct 68 ms 15864 KB Output is correct
4 Correct 17 ms 7168 KB Output is correct
5 Correct 16 ms 6400 KB Output is correct
6 Correct 25 ms 8192 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 41 ms 10872 KB Output is correct
9 Correct 56 ms 13688 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 117 ms 15496 KB Output is correct
12 Correct 181 ms 17272 KB Output is correct
13 Correct 8 ms 5248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 19060 KB Output is correct
2 Correct 101 ms 18804 KB Output is correct
3 Correct 68 ms 15864 KB Output is correct
4 Correct 17 ms 7168 KB Output is correct
5 Correct 16 ms 6400 KB Output is correct
6 Correct 25 ms 8192 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 41 ms 10872 KB Output is correct
9 Correct 56 ms 13688 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 117 ms 15496 KB Output is correct
12 Correct 181 ms 17272 KB Output is correct
13 Correct 8 ms 5248 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 4992 KB Output is correct
17 Correct 7 ms 4992 KB Output is correct
18 Correct 10 ms 4992 KB Output is correct
19 Correct 7 ms 4992 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 8 ms 4992 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 7 ms 4992 KB Output is correct
26 Correct 7 ms 4992 KB Output is correct
27 Correct 7 ms 4992 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 7 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 7 ms 4992 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 7 ms 4992 KB Output is correct
35 Correct 7 ms 5120 KB Output is correct
36 Correct 7 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 8 ms 4992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 19060 KB Output is correct
2 Correct 101 ms 18804 KB Output is correct
3 Correct 68 ms 15864 KB Output is correct
4 Correct 17 ms 7168 KB Output is correct
5 Correct 16 ms 6400 KB Output is correct
6 Correct 25 ms 8192 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 41 ms 10872 KB Output is correct
9 Correct 56 ms 13688 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 117 ms 15496 KB Output is correct
12 Correct 181 ms 17272 KB Output is correct
13 Correct 8 ms 5248 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 4992 KB Output is correct
17 Correct 7 ms 4992 KB Output is correct
18 Correct 10 ms 4992 KB Output is correct
19 Correct 7 ms 4992 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 8 ms 4992 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 7 ms 4992 KB Output is correct
26 Correct 7 ms 4992 KB Output is correct
27 Correct 7 ms 4992 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 7 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 7 ms 4992 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 7 ms 4992 KB Output is correct
35 Correct 7 ms 5120 KB Output is correct
36 Correct 7 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 8 ms 4992 KB Output is correct
39 Correct 90 ms 19060 KB Output is correct
40 Correct 90 ms 18804 KB Output is correct
41 Correct 65 ms 15864 KB Output is correct
42 Correct 17 ms 7168 KB Output is correct
43 Correct 7 ms 4992 KB Output is correct
44 Correct 8 ms 4992 KB Output is correct
45 Correct 7 ms 4992 KB Output is correct
46 Correct 7 ms 5120 KB Output is correct
47 Correct 8 ms 4992 KB Output is correct
48 Correct 7 ms 5120 KB Output is correct
49 Correct 8 ms 4992 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 7 ms 5120 KB Output is correct
52 Correct 9 ms 4992 KB Output is correct
53 Correct 10 ms 4992 KB Output is correct
54 Correct 8 ms 5248 KB Output is correct
55 Correct 9 ms 4992 KB Output is correct
56 Correct 7 ms 4992 KB Output is correct
57 Correct 140 ms 15988 KB Output is correct
58 Correct 230 ms 15736 KB Output is correct
59 Correct 140 ms 16120 KB Output is correct
60 Correct 150 ms 15868 KB Output is correct
61 Correct 178 ms 16580 KB Output is correct
62 Correct 140 ms 16248 KB Output is correct
63 Correct 142 ms 16224 KB Output is correct
64 Correct 131 ms 16172 KB Output is correct
65 Correct 139 ms 16444 KB Output is correct
66 Correct 127 ms 16452 KB Output is correct
67 Correct 134 ms 16144 KB Output is correct
68 Correct 129 ms 16176 KB Output is correct
69 Correct 182 ms 16132 KB Output is correct
70 Correct 132 ms 16120 KB Output is correct
71 Correct 7 ms 4992 KB Output is correct
72 Correct 12 ms 5376 KB Output is correct
73 Correct 9 ms 5376 KB Output is correct
74 Correct 9 ms 5376 KB Output is correct
75 Correct 10 ms 5376 KB Output is correct
76 Correct 10 ms 5376 KB Output is correct
77 Correct 9 ms 5376 KB Output is correct
78 Correct 10 ms 5376 KB Output is correct
79 Correct 9 ms 5352 KB Output is correct
80 Correct 131 ms 16120 KB Output is correct
81 Correct 136 ms 16128 KB Output is correct
82 Correct 129 ms 16488 KB Output is correct
83 Correct 201 ms 16476 KB Output is correct
84 Correct 10 ms 5376 KB Output is correct
85 Correct 8 ms 5376 KB Output is correct
86 Correct 9 ms 5376 KB Output is correct
87 Correct 9 ms 5376 KB Output is correct
88 Correct 9 ms 5376 KB Output is correct
89 Correct 9 ms 5376 KB Output is correct
90 Correct 11 ms 5376 KB Output is correct
91 Correct 9 ms 5376 KB Output is correct
92 Correct 9 ms 5376 KB Output is correct
93 Correct 9 ms 5376 KB Output is correct
94 Correct 8 ms 4992 KB Output is correct
95 Correct 7 ms 4992 KB Output is correct
96 Correct 7 ms 4992 KB Output is correct
97 Correct 7 ms 4992 KB Output is correct
98 Correct 7 ms 4992 KB Output is correct
99 Correct 8 ms 4992 KB Output is correct
100 Correct 9 ms 4992 KB Output is correct
101 Correct 7 ms 5044 KB Output is correct
102 Correct 7 ms 4992 KB Output is correct
103 Correct 7 ms 5120 KB Output is correct
104 Correct 16 ms 6272 KB Output is correct
105 Correct 24 ms 8184 KB Output is correct
106 Correct 8 ms 5120 KB Output is correct
107 Correct 43 ms 11000 KB Output is correct
108 Correct 58 ms 13624 KB Output is correct
109 Correct 8 ms 5120 KB Output is correct
110 Correct 93 ms 15404 KB Output is correct
111 Correct 104 ms 17272 KB Output is correct
112 Correct 7 ms 5120 KB Output is correct
113 Correct 151 ms 24028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 11516 KB Output is correct
2 Incorrect 39 ms 11636 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 19060 KB Output is correct
2 Correct 101 ms 18804 KB Output is correct
3 Correct 68 ms 15864 KB Output is correct
4 Correct 17 ms 7168 KB Output is correct
5 Correct 16 ms 6400 KB Output is correct
6 Correct 25 ms 8192 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 41 ms 10872 KB Output is correct
9 Correct 56 ms 13688 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 117 ms 15496 KB Output is correct
12 Correct 181 ms 17272 KB Output is correct
13 Correct 8 ms 5248 KB Output is correct
14 Correct 9 ms 5120 KB Output is correct
15 Correct 8 ms 5248 KB Output is correct
16 Correct 9 ms 5376 KB Output is correct
17 Correct 7 ms 5120 KB Output is correct
18 Correct 8 ms 5248 KB Output is correct
19 Correct 12 ms 5376 KB Output is correct
20 Incorrect 8 ms 5120 KB Output isn't correct
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 97 ms 19060 KB Output is correct
2 Correct 101 ms 18804 KB Output is correct
3 Correct 68 ms 15864 KB Output is correct
4 Correct 17 ms 7168 KB Output is correct
5 Correct 16 ms 6400 KB Output is correct
6 Correct 25 ms 8192 KB Output is correct
7 Correct 7 ms 5120 KB Output is correct
8 Correct 41 ms 10872 KB Output is correct
9 Correct 56 ms 13688 KB Output is correct
10 Correct 8 ms 5120 KB Output is correct
11 Correct 117 ms 15496 KB Output is correct
12 Correct 181 ms 17272 KB Output is correct
13 Correct 8 ms 5248 KB Output is correct
14 Correct 8 ms 4992 KB Output is correct
15 Correct 7 ms 4992 KB Output is correct
16 Correct 7 ms 4992 KB Output is correct
17 Correct 7 ms 4992 KB Output is correct
18 Correct 10 ms 4992 KB Output is correct
19 Correct 7 ms 4992 KB Output is correct
20 Correct 7 ms 5120 KB Output is correct
21 Correct 7 ms 4992 KB Output is correct
22 Correct 8 ms 4992 KB Output is correct
23 Correct 7 ms 5120 KB Output is correct
24 Correct 7 ms 5248 KB Output is correct
25 Correct 7 ms 4992 KB Output is correct
26 Correct 7 ms 4992 KB Output is correct
27 Correct 7 ms 4992 KB Output is correct
28 Correct 7 ms 4992 KB Output is correct
29 Correct 7 ms 4992 KB Output is correct
30 Correct 7 ms 4992 KB Output is correct
31 Correct 7 ms 4992 KB Output is correct
32 Correct 7 ms 4992 KB Output is correct
33 Correct 7 ms 4992 KB Output is correct
34 Correct 7 ms 4992 KB Output is correct
35 Correct 7 ms 5120 KB Output is correct
36 Correct 7 ms 4992 KB Output is correct
37 Correct 7 ms 4992 KB Output is correct
38 Correct 8 ms 4992 KB Output is correct
39 Correct 90 ms 19060 KB Output is correct
40 Correct 90 ms 18804 KB Output is correct
41 Correct 65 ms 15864 KB Output is correct
42 Correct 17 ms 7168 KB Output is correct
43 Correct 7 ms 4992 KB Output is correct
44 Correct 8 ms 4992 KB Output is correct
45 Correct 7 ms 4992 KB Output is correct
46 Correct 7 ms 5120 KB Output is correct
47 Correct 8 ms 4992 KB Output is correct
48 Correct 7 ms 5120 KB Output is correct
49 Correct 8 ms 4992 KB Output is correct
50 Correct 7 ms 4992 KB Output is correct
51 Correct 7 ms 5120 KB Output is correct
52 Correct 9 ms 4992 KB Output is correct
53 Correct 10 ms 4992 KB Output is correct
54 Correct 8 ms 5248 KB Output is correct
55 Correct 9 ms 4992 KB Output is correct
56 Correct 7 ms 4992 KB Output is correct
57 Correct 140 ms 15988 KB Output is correct
58 Correct 230 ms 15736 KB Output is correct
59 Correct 140 ms 16120 KB Output is correct
60 Correct 150 ms 15868 KB Output is correct
61 Correct 178 ms 16580 KB Output is correct
62 Correct 140 ms 16248 KB Output is correct
63 Correct 142 ms 16224 KB Output is correct
64 Correct 131 ms 16172 KB Output is correct
65 Correct 139 ms 16444 KB Output is correct
66 Correct 127 ms 16452 KB Output is correct
67 Correct 134 ms 16144 KB Output is correct
68 Correct 129 ms 16176 KB Output is correct
69 Correct 182 ms 16132 KB Output is correct
70 Correct 132 ms 16120 KB Output is correct
71 Correct 7 ms 4992 KB Output is correct
72 Correct 12 ms 5376 KB Output is correct
73 Correct 9 ms 5376 KB Output is correct
74 Correct 9 ms 5376 KB Output is correct
75 Correct 10 ms 5376 KB Output is correct
76 Correct 10 ms 5376 KB Output is correct
77 Correct 9 ms 5376 KB Output is correct
78 Correct 10 ms 5376 KB Output is correct
79 Correct 9 ms 5352 KB Output is correct
80 Correct 131 ms 16120 KB Output is correct
81 Correct 136 ms 16128 KB Output is correct
82 Correct 129 ms 16488 KB Output is correct
83 Correct 201 ms 16476 KB Output is correct
84 Correct 10 ms 5376 KB Output is correct
85 Correct 8 ms 5376 KB Output is correct
86 Correct 9 ms 5376 KB Output is correct
87 Correct 9 ms 5376 KB Output is correct
88 Correct 9 ms 5376 KB Output is correct
89 Correct 9 ms 5376 KB Output is correct
90 Correct 11 ms 5376 KB Output is correct
91 Correct 9 ms 5376 KB Output is correct
92 Correct 9 ms 5376 KB Output is correct
93 Correct 9 ms 5376 KB Output is correct
94 Correct 8 ms 4992 KB Output is correct
95 Correct 7 ms 4992 KB Output is correct
96 Correct 7 ms 4992 KB Output is correct
97 Correct 7 ms 4992 KB Output is correct
98 Correct 7 ms 4992 KB Output is correct
99 Correct 8 ms 4992 KB Output is correct
100 Correct 9 ms 4992 KB Output is correct
101 Correct 7 ms 5044 KB Output is correct
102 Correct 7 ms 4992 KB Output is correct
103 Correct 7 ms 5120 KB Output is correct
104 Correct 16 ms 6272 KB Output is correct
105 Correct 24 ms 8184 KB Output is correct
106 Correct 8 ms 5120 KB Output is correct
107 Correct 43 ms 11000 KB Output is correct
108 Correct 58 ms 13624 KB Output is correct
109 Correct 8 ms 5120 KB Output is correct
110 Correct 93 ms 15404 KB Output is correct
111 Correct 104 ms 17272 KB Output is correct
112 Correct 7 ms 5120 KB Output is correct
113 Correct 151 ms 24028 KB Output is correct
114 Correct 38 ms 11516 KB Output is correct
115 Incorrect 39 ms 11636 KB Output isn't correct
116 Halted 0 ms 0 KB -