답안 #1100957

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100957 2024-10-15T05:29:09 Z alexander707070 꿈 (IOI13_dreaming) C++14
47 / 100
59 ms 23228 KB
#include<bits/stdc++.h>
#include "dreaming.h"

#define MAXN 100007
using namespace std;

const int inf=1e9;

int n,m,len;
vector< pair<int,int> > v[MAXN];
bool vis[MAXN];
int down[MAXN],up[MAXN],mindist,maxdist;
vector<int> w;

void dfs(int x,int p){
	vis[x]=true;

	for(int i=0;i<v[x].size();i++){
		if(v[x][i].first==p)continue;
		dfs(v[x][i].first,x);

		down[x]=max(down[x],down[v[x][i].first]+v[x][i].second);
	}
}

void dfs2(int x,int p){
	vis[x]=true;

	multiset<int> s;
	for(int i=0;i<v[x].size();i++){
		if(v[x][i].first==p)continue;
		s.insert({down[v[x][i].first]+v[x][i].second});
	}

	for(int i=0;i<v[x].size();i++){
		if(v[x][i].first==p)continue;
		
		s.erase(s.find(down[v[x][i].first]+v[x][i].second));

		up[v[x][i].first]=up[x];
		if(!s.empty())up[v[x][i].first]=max(up[v[x][i].first], *s.rbegin());
		up[v[x][i].first]+=v[x][i].second;

		dfs2(v[x][i].first,x);

		s.insert(down[v[x][i].first]+v[x][i].second);
	}

	mindist=min(mindist,max(down[x],up[x]));
	maxdist=max(maxdist,max(down[x],up[x]));
}

int travelTime(int N, int M, int L, int A[], int B[], int T[]) {
//int travelTime(int N, int M, int L, vector<int> A, vector<int> B, vector<int> T) {
    n=N; m=M; len=L;

	for(int i=1;i<=m;i++){
		A[i-1]++; B[i-1]++;
		v[A[i-1]].push_back({B[i-1],T[i-1]});
		v[B[i-1]].push_back({A[i-1],T[i-1]});
	}

	for(int i=1;i<=n;i++){
		if(!vis[i])dfs(i,0);
	}

	for(int i=1;i<=n;i++)vis[i]=false;

	for(int i=1;i<=n;i++){
		if(!vis[i]){
			mindist=inf; dfs2(i,0);
			w.push_back(mindist);
		}
	}

	sort(w.begin(),w.end());
	reverse(w.begin(),w.end());
	
	if(w.size()==2){
		return max(maxdist,w[0]+w[1]+len);
	}else{
		return max(max(maxdist,w[0]+w[1]+len),w[1]+w[2]+2*len);
	}
}

/*int main(){

	cout<<travelTime(12,8,2,{0,8,2,5,5,1,1,10},{8,2,7,11,1,3,9,6},{4,2,4,3,7,1,5,3})<<"\n";
 
	return 0;
}*/

Compilation message

dreaming.cpp: In function 'void dfs(int, int)':
dreaming.cpp:18:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |  for(int i=0;i<v[x].size();i++){
      |              ~^~~~~~~~~~~~
dreaming.cpp: In function 'void dfs2(int, int)':
dreaming.cpp:30:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |  for(int i=0;i<v[x].size();i++){
      |              ~^~~~~~~~~~~~
dreaming.cpp:35:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  for(int i=0;i<v[x].size();i++){
      |              ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 15432 KB Output is correct
2 Correct 40 ms 14928 KB Output is correct
3 Correct 28 ms 14672 KB Output is correct
4 Correct 7 ms 6224 KB Output is correct
5 Correct 6 ms 5456 KB Output is correct
6 Correct 11 ms 6992 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 21 ms 9052 KB Output is correct
9 Correct 26 ms 12368 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Correct 35 ms 12008 KB Output is correct
12 Correct 39 ms 13720 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4688 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4688 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4536 KB Output is correct
16 Correct 1 ms 4600 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4504 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 2 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 15432 KB Output is correct
2 Correct 40 ms 14928 KB Output is correct
3 Correct 28 ms 14672 KB Output is correct
4 Correct 7 ms 6224 KB Output is correct
5 Correct 6 ms 5456 KB Output is correct
6 Correct 11 ms 6992 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 21 ms 9052 KB Output is correct
9 Correct 26 ms 12368 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Correct 35 ms 12008 KB Output is correct
12 Correct 39 ms 13720 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4688 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4688 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4536 KB Output is correct
29 Correct 1 ms 4600 KB Output is correct
30 Correct 1 ms 4688 KB Output is correct
31 Correct 1 ms 4432 KB Output is correct
32 Correct 1 ms 4432 KB Output is correct
33 Correct 1 ms 4504 KB Output is correct
34 Correct 1 ms 4432 KB Output is correct
35 Correct 1 ms 4432 KB Output is correct
36 Correct 1 ms 4432 KB Output is correct
37 Correct 1 ms 4432 KB Output is correct
38 Correct 2 ms 4432 KB Output is correct
39 Correct 40 ms 15440 KB Output is correct
40 Correct 40 ms 14908 KB Output is correct
41 Correct 27 ms 14528 KB Output is correct
42 Correct 9 ms 6224 KB Output is correct
43 Correct 2 ms 4432 KB Output is correct
44 Correct 1 ms 4688 KB Output is correct
45 Correct 1 ms 4600 KB Output is correct
46 Correct 1 ms 4432 KB Output is correct
47 Correct 1 ms 4432 KB Output is correct
48 Correct 1 ms 4432 KB Output is correct
49 Correct 1 ms 4432 KB Output is correct
50 Correct 1 ms 4432 KB Output is correct
51 Correct 1 ms 4432 KB Output is correct
52 Correct 1 ms 4432 KB Output is correct
53 Correct 1 ms 4432 KB Output is correct
54 Correct 1 ms 4604 KB Output is correct
55 Correct 1 ms 4432 KB Output is correct
56 Correct 1 ms 4432 KB Output is correct
57 Correct 37 ms 8784 KB Output is correct
58 Correct 38 ms 8676 KB Output is correct
59 Correct 39 ms 8776 KB Output is correct
60 Correct 45 ms 8656 KB Output is correct
61 Correct 40 ms 8528 KB Output is correct
62 Correct 57 ms 8536 KB Output is correct
63 Correct 37 ms 8520 KB Output is correct
64 Correct 48 ms 8544 KB Output is correct
65 Correct 38 ms 8520 KB Output is correct
66 Correct 40 ms 8272 KB Output is correct
67 Correct 41 ms 8784 KB Output is correct
68 Correct 44 ms 8776 KB Output is correct
69 Correct 40 ms 8776 KB Output is correct
70 Correct 46 ms 8776 KB Output is correct
71 Correct 1 ms 4432 KB Output is correct
72 Correct 2 ms 4688 KB Output is correct
73 Correct 2 ms 4688 KB Output is correct
74 Correct 2 ms 4688 KB Output is correct
75 Correct 2 ms 4688 KB Output is correct
76 Correct 2 ms 4860 KB Output is correct
77 Correct 2 ms 4688 KB Output is correct
78 Correct 2 ms 4688 KB Output is correct
79 Correct 2 ms 4688 KB Output is correct
80 Correct 39 ms 8776 KB Output is correct
81 Correct 40 ms 8760 KB Output is correct
82 Correct 39 ms 8528 KB Output is correct
83 Correct 39 ms 8520 KB Output is correct
84 Correct 2 ms 4688 KB Output is correct
85 Correct 3 ms 4688 KB Output is correct
86 Correct 2 ms 4688 KB Output is correct
87 Correct 2 ms 4688 KB Output is correct
88 Correct 2 ms 4688 KB Output is correct
89 Correct 2 ms 4856 KB Output is correct
90 Correct 2 ms 4688 KB Output is correct
91 Correct 2 ms 4688 KB Output is correct
92 Correct 2 ms 4688 KB Output is correct
93 Correct 4 ms 4688 KB Output is correct
94 Correct 1 ms 4688 KB Output is correct
95 Correct 1 ms 4688 KB Output is correct
96 Correct 1 ms 4432 KB Output is correct
97 Correct 1 ms 4432 KB Output is correct
98 Correct 1 ms 4432 KB Output is correct
99 Correct 1 ms 4432 KB Output is correct
100 Correct 2 ms 4688 KB Output is correct
101 Correct 2 ms 4444 KB Output is correct
102 Correct 2 ms 4432 KB Output is correct
103 Correct 2 ms 4536 KB Output is correct
104 Correct 5 ms 5456 KB Output is correct
105 Correct 11 ms 7048 KB Output is correct
106 Correct 2 ms 4688 KB Output is correct
107 Correct 21 ms 9040 KB Output is correct
108 Correct 28 ms 12360 KB Output is correct
109 Correct 2 ms 4688 KB Output is correct
110 Correct 38 ms 12008 KB Output is correct
111 Correct 50 ms 13764 KB Output is correct
112 Correct 2 ms 4856 KB Output is correct
113 Correct 59 ms 23228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 7116 KB Output is correct
2 Correct 16 ms 7120 KB Output is correct
3 Correct 17 ms 6992 KB Output is correct
4 Correct 16 ms 7120 KB Output is correct
5 Correct 16 ms 6992 KB Output is correct
6 Correct 16 ms 7380 KB Output is correct
7 Correct 16 ms 7124 KB Output is correct
8 Correct 16 ms 6992 KB Output is correct
9 Correct 14 ms 6992 KB Output is correct
10 Correct 17 ms 7104 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 5 ms 5324 KB Output is correct
13 Correct 5 ms 5324 KB Output is correct
14 Correct 5 ms 5324 KB Output is correct
15 Correct 5 ms 5324 KB Output is correct
16 Correct 5 ms 5324 KB Output is correct
17 Correct 5 ms 5324 KB Output is correct
18 Correct 5 ms 5340 KB Output is correct
19 Correct 4 ms 5324 KB Output is correct
20 Incorrect 2 ms 4432 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 1 ms 4432 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4688 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4688 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4536 KB Output is correct
16 Correct 1 ms 4600 KB Output is correct
17 Correct 1 ms 4688 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4504 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 2 ms 4432 KB Output is correct
26 Correct 2 ms 4688 KB Output is correct
27 Correct 2 ms 4692 KB Output is correct
28 Correct 2 ms 4692 KB Output is correct
29 Correct 2 ms 4692 KB Output is correct
30 Correct 2 ms 4692 KB Output is correct
31 Correct 3 ms 4692 KB Output is correct
32 Correct 1 ms 4692 KB Output is correct
33 Correct 3 ms 4692 KB Output is correct
34 Correct 3 ms 4692 KB Output is correct
35 Correct 2 ms 4436 KB Output is correct
36 Correct 2 ms 4692 KB Output is correct
37 Correct 1 ms 4436 KB Output is correct
38 Correct 1 ms 4692 KB Output is correct
39 Correct 2 ms 4692 KB Output is correct
40 Correct 2 ms 4436 KB Output is correct
41 Correct 1 ms 4512 KB Output is correct
42 Correct 2 ms 4436 KB Output is correct
43 Correct 2 ms 4692 KB Output is correct
44 Correct 1 ms 4676 KB Output is correct
45 Correct 1 ms 4856 KB Output is correct
46 Correct 1 ms 4856 KB Output is correct
47 Correct 1 ms 4436 KB Output is correct
48 Correct 2 ms 4444 KB Output is correct
49 Correct 1 ms 4600 KB Output is correct
50 Correct 1 ms 4448 KB Output is correct
51 Correct 1 ms 4448 KB Output is correct
52 Incorrect 1 ms 4448 KB Output isn't correct
53 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 41 ms 15432 KB Output is correct
2 Correct 40 ms 14928 KB Output is correct
3 Correct 28 ms 14672 KB Output is correct
4 Correct 7 ms 6224 KB Output is correct
5 Correct 6 ms 5456 KB Output is correct
6 Correct 11 ms 6992 KB Output is correct
7 Correct 1 ms 4688 KB Output is correct
8 Correct 21 ms 9052 KB Output is correct
9 Correct 26 ms 12368 KB Output is correct
10 Correct 1 ms 4688 KB Output is correct
11 Correct 35 ms 12008 KB Output is correct
12 Correct 39 ms 13720 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 1 ms 4688 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4688 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4536 KB Output is correct
29 Correct 1 ms 4600 KB Output is correct
30 Correct 1 ms 4688 KB Output is correct
31 Correct 1 ms 4432 KB Output is correct
32 Correct 1 ms 4432 KB Output is correct
33 Correct 1 ms 4504 KB Output is correct
34 Correct 1 ms 4432 KB Output is correct
35 Correct 1 ms 4432 KB Output is correct
36 Correct 1 ms 4432 KB Output is correct
37 Correct 1 ms 4432 KB Output is correct
38 Correct 2 ms 4432 KB Output is correct
39 Correct 40 ms 15440 KB Output is correct
40 Correct 40 ms 14908 KB Output is correct
41 Correct 27 ms 14528 KB Output is correct
42 Correct 9 ms 6224 KB Output is correct
43 Correct 2 ms 4432 KB Output is correct
44 Correct 1 ms 4688 KB Output is correct
45 Correct 1 ms 4600 KB Output is correct
46 Correct 1 ms 4432 KB Output is correct
47 Correct 1 ms 4432 KB Output is correct
48 Correct 1 ms 4432 KB Output is correct
49 Correct 1 ms 4432 KB Output is correct
50 Correct 1 ms 4432 KB Output is correct
51 Correct 1 ms 4432 KB Output is correct
52 Correct 1 ms 4432 KB Output is correct
53 Correct 1 ms 4432 KB Output is correct
54 Correct 1 ms 4604 KB Output is correct
55 Correct 1 ms 4432 KB Output is correct
56 Correct 1 ms 4432 KB Output is correct
57 Correct 37 ms 8784 KB Output is correct
58 Correct 38 ms 8676 KB Output is correct
59 Correct 39 ms 8776 KB Output is correct
60 Correct 45 ms 8656 KB Output is correct
61 Correct 40 ms 8528 KB Output is correct
62 Correct 57 ms 8536 KB Output is correct
63 Correct 37 ms 8520 KB Output is correct
64 Correct 48 ms 8544 KB Output is correct
65 Correct 38 ms 8520 KB Output is correct
66 Correct 40 ms 8272 KB Output is correct
67 Correct 41 ms 8784 KB Output is correct
68 Correct 44 ms 8776 KB Output is correct
69 Correct 40 ms 8776 KB Output is correct
70 Correct 46 ms 8776 KB Output is correct
71 Correct 1 ms 4432 KB Output is correct
72 Correct 2 ms 4688 KB Output is correct
73 Correct 2 ms 4688 KB Output is correct
74 Correct 2 ms 4688 KB Output is correct
75 Correct 2 ms 4688 KB Output is correct
76 Correct 2 ms 4860 KB Output is correct
77 Correct 2 ms 4688 KB Output is correct
78 Correct 2 ms 4688 KB Output is correct
79 Correct 2 ms 4688 KB Output is correct
80 Correct 39 ms 8776 KB Output is correct
81 Correct 40 ms 8760 KB Output is correct
82 Correct 39 ms 8528 KB Output is correct
83 Correct 39 ms 8520 KB Output is correct
84 Correct 2 ms 4688 KB Output is correct
85 Correct 3 ms 4688 KB Output is correct
86 Correct 2 ms 4688 KB Output is correct
87 Correct 2 ms 4688 KB Output is correct
88 Correct 2 ms 4688 KB Output is correct
89 Correct 2 ms 4856 KB Output is correct
90 Correct 2 ms 4688 KB Output is correct
91 Correct 2 ms 4688 KB Output is correct
92 Correct 2 ms 4688 KB Output is correct
93 Correct 4 ms 4688 KB Output is correct
94 Correct 1 ms 4688 KB Output is correct
95 Correct 1 ms 4688 KB Output is correct
96 Correct 1 ms 4432 KB Output is correct
97 Correct 1 ms 4432 KB Output is correct
98 Correct 1 ms 4432 KB Output is correct
99 Correct 1 ms 4432 KB Output is correct
100 Correct 2 ms 4688 KB Output is correct
101 Correct 2 ms 4444 KB Output is correct
102 Correct 2 ms 4432 KB Output is correct
103 Correct 2 ms 4536 KB Output is correct
104 Correct 5 ms 5456 KB Output is correct
105 Correct 11 ms 7048 KB Output is correct
106 Correct 2 ms 4688 KB Output is correct
107 Correct 21 ms 9040 KB Output is correct
108 Correct 28 ms 12360 KB Output is correct
109 Correct 2 ms 4688 KB Output is correct
110 Correct 38 ms 12008 KB Output is correct
111 Correct 50 ms 13764 KB Output is correct
112 Correct 2 ms 4856 KB Output is correct
113 Correct 59 ms 23228 KB Output is correct
114 Correct 22 ms 7116 KB Output is correct
115 Correct 16 ms 7120 KB Output is correct
116 Correct 17 ms 6992 KB Output is correct
117 Correct 16 ms 7120 KB Output is correct
118 Correct 16 ms 6992 KB Output is correct
119 Correct 16 ms 7380 KB Output is correct
120 Correct 16 ms 7124 KB Output is correct
121 Correct 16 ms 6992 KB Output is correct
122 Correct 14 ms 6992 KB Output is correct
123 Correct 17 ms 7104 KB Output is correct
124 Correct 1 ms 4432 KB Output is correct
125 Correct 5 ms 5324 KB Output is correct
126 Correct 5 ms 5324 KB Output is correct
127 Correct 5 ms 5324 KB Output is correct
128 Correct 5 ms 5324 KB Output is correct
129 Correct 5 ms 5324 KB Output is correct
130 Correct 5 ms 5324 KB Output is correct
131 Correct 5 ms 5340 KB Output is correct
132 Correct 4 ms 5324 KB Output is correct
133 Incorrect 2 ms 4432 KB Output isn't correct
134 Halted 0 ms 0 KB -