답안 #1100956

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100956 2024-10-15T05:28:26 Z alexander707070 꿈 (IOI13_dreaming) C++14
47 / 100
56 ms 24940 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(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 38 ms 15396 KB Output is correct
2 Correct 39 ms 16088 KB Output is correct
3 Correct 30 ms 15684 KB Output is correct
4 Correct 7 ms 6228 KB Output is correct
5 Correct 5 ms 5460 KB Output is correct
6 Correct 12 ms 7252 KB Output is correct
7 Correct 2 ms 4692 KB Output is correct
8 Correct 20 ms 9556 KB Output is correct
9 Correct 29 ms 13140 KB Output is correct
10 Correct 2 ms 4692 KB Output is correct
11 Correct 38 ms 13148 KB Output is correct
12 Correct 42 ms 14932 KB Output is correct
13 Correct 2 ms 4692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4688 KB Output is correct
2 Correct 1 ms 4436 KB Output is correct
3 Correct 2 ms 4600 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 1 ms 4436 KB Output is correct
12 Correct 1 ms 4436 KB Output is correct
13 Correct 1 ms 4860 KB Output is correct
14 Correct 1 ms 4436 KB Output is correct
15 Correct 1 ms 4436 KB Output is correct
16 Correct 2 ms 4692 KB Output is correct
17 Correct 1 ms 4692 KB Output is correct
18 Correct 1 ms 4436 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 1 ms 4436 KB Output is correct
21 Correct 1 ms 4692 KB Output is correct
22 Correct 1 ms 4436 KB Output is correct
23 Correct 1 ms 4436 KB Output is correct
24 Correct 1 ms 4436 KB Output is correct
25 Correct 1 ms 4436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 15396 KB Output is correct
2 Correct 39 ms 16088 KB Output is correct
3 Correct 30 ms 15684 KB Output is correct
4 Correct 7 ms 6228 KB Output is correct
5 Correct 5 ms 5460 KB Output is correct
6 Correct 12 ms 7252 KB Output is correct
7 Correct 2 ms 4692 KB Output is correct
8 Correct 20 ms 9556 KB Output is correct
9 Correct 29 ms 13140 KB Output is correct
10 Correct 2 ms 4692 KB Output is correct
11 Correct 38 ms 13148 KB Output is correct
12 Correct 42 ms 14932 KB Output is correct
13 Correct 2 ms 4692 KB Output is correct
14 Correct 1 ms 4688 KB Output is correct
15 Correct 1 ms 4436 KB Output is correct
16 Correct 2 ms 4600 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 1 ms 4436 KB Output is correct
19 Correct 1 ms 4436 KB Output is correct
20 Correct 1 ms 4436 KB Output is correct
21 Correct 1 ms 4436 KB Output is correct
22 Correct 1 ms 4436 KB Output is correct
23 Correct 2 ms 4436 KB Output is correct
24 Correct 1 ms 4436 KB Output is correct
25 Correct 1 ms 4436 KB Output is correct
26 Correct 1 ms 4860 KB Output is correct
27 Correct 1 ms 4436 KB Output is correct
28 Correct 1 ms 4436 KB Output is correct
29 Correct 2 ms 4692 KB Output is correct
30 Correct 1 ms 4692 KB Output is correct
31 Correct 1 ms 4436 KB Output is correct
32 Correct 1 ms 4600 KB Output is correct
33 Correct 1 ms 4436 KB Output is correct
34 Correct 1 ms 4692 KB Output is correct
35 Correct 1 ms 4436 KB Output is correct
36 Correct 1 ms 4436 KB Output is correct
37 Correct 1 ms 4436 KB Output is correct
38 Correct 1 ms 4436 KB Output is correct
39 Correct 36 ms 16724 KB Output is correct
40 Correct 36 ms 16204 KB Output is correct
41 Correct 26 ms 15700 KB Output is correct
42 Correct 8 ms 6228 KB Output is correct
43 Correct 1 ms 4436 KB Output is correct
44 Correct 2 ms 4436 KB Output is correct
45 Correct 2 ms 4436 KB Output is correct
46 Correct 2 ms 4600 KB Output is correct
47 Correct 1 ms 4436 KB Output is correct
48 Correct 2 ms 4600 KB Output is correct
49 Correct 1 ms 4436 KB Output is correct
50 Correct 1 ms 4436 KB Output is correct
51 Correct 1 ms 4436 KB Output is correct
52 Correct 1 ms 4604 KB Output is correct
53 Correct 1 ms 4436 KB Output is correct
54 Correct 1 ms 4436 KB Output is correct
55 Correct 1 ms 4692 KB Output is correct
56 Correct 1 ms 4604 KB Output is correct
57 Correct 46 ms 10180 KB Output is correct
58 Correct 38 ms 10180 KB Output is correct
59 Correct 40 ms 10080 KB Output is correct
60 Correct 40 ms 10068 KB Output is correct
61 Correct 41 ms 10060 KB Output is correct
62 Correct 40 ms 10204 KB Output is correct
63 Correct 39 ms 9872 KB Output is correct
64 Correct 38 ms 9884 KB Output is correct
65 Correct 45 ms 9908 KB Output is correct
66 Correct 39 ms 10084 KB Output is correct
67 Correct 40 ms 10068 KB Output is correct
68 Correct 40 ms 10060 KB Output is correct
69 Correct 41 ms 10316 KB Output is correct
70 Correct 41 ms 10324 KB Output is correct
71 Correct 1 ms 4436 KB Output is correct
72 Correct 2 ms 4692 KB Output is correct
73 Correct 2 ms 4692 KB Output is correct
74 Correct 3 ms 4860 KB Output is correct
75 Correct 3 ms 4692 KB Output is correct
76 Correct 2 ms 4692 KB Output is correct
77 Correct 2 ms 4692 KB Output is correct
78 Correct 2 ms 4856 KB Output is correct
79 Correct 3 ms 4856 KB Output is correct
80 Correct 40 ms 10068 KB Output is correct
81 Correct 46 ms 10060 KB Output is correct
82 Correct 40 ms 10068 KB Output is correct
83 Correct 45 ms 10060 KB Output is correct
84 Correct 2 ms 4692 KB Output is correct
85 Correct 2 ms 4704 KB Output is correct
86 Correct 2 ms 4692 KB Output is correct
87 Correct 3 ms 4692 KB Output is correct
88 Correct 2 ms 4692 KB Output is correct
89 Correct 2 ms 4692 KB Output is correct
90 Correct 2 ms 4876 KB Output is correct
91 Correct 2 ms 4704 KB Output is correct
92 Correct 2 ms 4856 KB Output is correct
93 Correct 2 ms 4780 KB Output is correct
94 Correct 1 ms 4692 KB Output is correct
95 Correct 1 ms 4692 KB Output is correct
96 Correct 1 ms 4436 KB Output is correct
97 Correct 1 ms 4448 KB Output is correct
98 Correct 1 ms 4448 KB Output is correct
99 Correct 1 ms 4704 KB Output is correct
100 Correct 1 ms 4436 KB Output is correct
101 Correct 1 ms 4436 KB Output is correct
102 Correct 1 ms 4684 KB Output is correct
103 Correct 2 ms 4436 KB Output is correct
104 Correct 5 ms 5460 KB Output is correct
105 Correct 10 ms 7352 KB Output is correct
106 Correct 1 ms 4860 KB Output is correct
107 Correct 19 ms 9620 KB Output is correct
108 Correct 26 ms 13140 KB Output is correct
109 Correct 2 ms 4692 KB Output is correct
110 Correct 33 ms 13240 KB Output is correct
111 Correct 37 ms 14924 KB Output is correct
112 Correct 1 ms 4692 KB Output is correct
113 Correct 56 ms 24940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 6992 KB Output is correct
2 Correct 14 ms 7072 KB Output is correct
3 Correct 14 ms 6992 KB Output is correct
4 Correct 15 ms 7132 KB Output is correct
5 Correct 15 ms 6992 KB Output is correct
6 Correct 15 ms 7380 KB Output is correct
7 Correct 15 ms 7140 KB Output is correct
8 Correct 14 ms 7004 KB Output is correct
9 Correct 14 ms 6992 KB Output is correct
10 Correct 17 ms 7212 KB Output is correct
11 Correct 1 ms 4600 KB Output is correct
12 Correct 4 ms 5324 KB Output is correct
13 Correct 5 ms 5324 KB Output is correct
14 Correct 4 ms 5324 KB Output is correct
15 Correct 4 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 5324 KB Output is correct
19 Correct 8 ms 5324 KB Output is correct
20 Incorrect 1 ms 4432 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4688 KB Output is correct
2 Correct 1 ms 4436 KB Output is correct
3 Correct 2 ms 4600 KB Output is correct
4 Correct 2 ms 4436 KB Output is correct
5 Correct 1 ms 4436 KB Output is correct
6 Correct 1 ms 4436 KB Output is correct
7 Correct 1 ms 4436 KB Output is correct
8 Correct 1 ms 4436 KB Output is correct
9 Correct 1 ms 4436 KB Output is correct
10 Correct 2 ms 4436 KB Output is correct
11 Correct 1 ms 4436 KB Output is correct
12 Correct 1 ms 4436 KB Output is correct
13 Correct 1 ms 4860 KB Output is correct
14 Correct 1 ms 4436 KB Output is correct
15 Correct 1 ms 4436 KB Output is correct
16 Correct 2 ms 4692 KB Output is correct
17 Correct 1 ms 4692 KB Output is correct
18 Correct 1 ms 4436 KB Output is correct
19 Correct 1 ms 4600 KB Output is correct
20 Correct 1 ms 4436 KB Output is correct
21 Correct 1 ms 4692 KB Output is correct
22 Correct 1 ms 4436 KB Output is correct
23 Correct 1 ms 4436 KB Output is correct
24 Correct 1 ms 4436 KB Output is correct
25 Correct 1 ms 4436 KB Output is correct
26 Incorrect 2 ms 4828 KB Output isn't correct
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 38 ms 15396 KB Output is correct
2 Correct 39 ms 16088 KB Output is correct
3 Correct 30 ms 15684 KB Output is correct
4 Correct 7 ms 6228 KB Output is correct
5 Correct 5 ms 5460 KB Output is correct
6 Correct 12 ms 7252 KB Output is correct
7 Correct 2 ms 4692 KB Output is correct
8 Correct 20 ms 9556 KB Output is correct
9 Correct 29 ms 13140 KB Output is correct
10 Correct 2 ms 4692 KB Output is correct
11 Correct 38 ms 13148 KB Output is correct
12 Correct 42 ms 14932 KB Output is correct
13 Correct 2 ms 4692 KB Output is correct
14 Correct 1 ms 4688 KB Output is correct
15 Correct 1 ms 4436 KB Output is correct
16 Correct 2 ms 4600 KB Output is correct
17 Correct 2 ms 4436 KB Output is correct
18 Correct 1 ms 4436 KB Output is correct
19 Correct 1 ms 4436 KB Output is correct
20 Correct 1 ms 4436 KB Output is correct
21 Correct 1 ms 4436 KB Output is correct
22 Correct 1 ms 4436 KB Output is correct
23 Correct 2 ms 4436 KB Output is correct
24 Correct 1 ms 4436 KB Output is correct
25 Correct 1 ms 4436 KB Output is correct
26 Correct 1 ms 4860 KB Output is correct
27 Correct 1 ms 4436 KB Output is correct
28 Correct 1 ms 4436 KB Output is correct
29 Correct 2 ms 4692 KB Output is correct
30 Correct 1 ms 4692 KB Output is correct
31 Correct 1 ms 4436 KB Output is correct
32 Correct 1 ms 4600 KB Output is correct
33 Correct 1 ms 4436 KB Output is correct
34 Correct 1 ms 4692 KB Output is correct
35 Correct 1 ms 4436 KB Output is correct
36 Correct 1 ms 4436 KB Output is correct
37 Correct 1 ms 4436 KB Output is correct
38 Correct 1 ms 4436 KB Output is correct
39 Correct 36 ms 16724 KB Output is correct
40 Correct 36 ms 16204 KB Output is correct
41 Correct 26 ms 15700 KB Output is correct
42 Correct 8 ms 6228 KB Output is correct
43 Correct 1 ms 4436 KB Output is correct
44 Correct 2 ms 4436 KB Output is correct
45 Correct 2 ms 4436 KB Output is correct
46 Correct 2 ms 4600 KB Output is correct
47 Correct 1 ms 4436 KB Output is correct
48 Correct 2 ms 4600 KB Output is correct
49 Correct 1 ms 4436 KB Output is correct
50 Correct 1 ms 4436 KB Output is correct
51 Correct 1 ms 4436 KB Output is correct
52 Correct 1 ms 4604 KB Output is correct
53 Correct 1 ms 4436 KB Output is correct
54 Correct 1 ms 4436 KB Output is correct
55 Correct 1 ms 4692 KB Output is correct
56 Correct 1 ms 4604 KB Output is correct
57 Correct 46 ms 10180 KB Output is correct
58 Correct 38 ms 10180 KB Output is correct
59 Correct 40 ms 10080 KB Output is correct
60 Correct 40 ms 10068 KB Output is correct
61 Correct 41 ms 10060 KB Output is correct
62 Correct 40 ms 10204 KB Output is correct
63 Correct 39 ms 9872 KB Output is correct
64 Correct 38 ms 9884 KB Output is correct
65 Correct 45 ms 9908 KB Output is correct
66 Correct 39 ms 10084 KB Output is correct
67 Correct 40 ms 10068 KB Output is correct
68 Correct 40 ms 10060 KB Output is correct
69 Correct 41 ms 10316 KB Output is correct
70 Correct 41 ms 10324 KB Output is correct
71 Correct 1 ms 4436 KB Output is correct
72 Correct 2 ms 4692 KB Output is correct
73 Correct 2 ms 4692 KB Output is correct
74 Correct 3 ms 4860 KB Output is correct
75 Correct 3 ms 4692 KB Output is correct
76 Correct 2 ms 4692 KB Output is correct
77 Correct 2 ms 4692 KB Output is correct
78 Correct 2 ms 4856 KB Output is correct
79 Correct 3 ms 4856 KB Output is correct
80 Correct 40 ms 10068 KB Output is correct
81 Correct 46 ms 10060 KB Output is correct
82 Correct 40 ms 10068 KB Output is correct
83 Correct 45 ms 10060 KB Output is correct
84 Correct 2 ms 4692 KB Output is correct
85 Correct 2 ms 4704 KB Output is correct
86 Correct 2 ms 4692 KB Output is correct
87 Correct 3 ms 4692 KB Output is correct
88 Correct 2 ms 4692 KB Output is correct
89 Correct 2 ms 4692 KB Output is correct
90 Correct 2 ms 4876 KB Output is correct
91 Correct 2 ms 4704 KB Output is correct
92 Correct 2 ms 4856 KB Output is correct
93 Correct 2 ms 4780 KB Output is correct
94 Correct 1 ms 4692 KB Output is correct
95 Correct 1 ms 4692 KB Output is correct
96 Correct 1 ms 4436 KB Output is correct
97 Correct 1 ms 4448 KB Output is correct
98 Correct 1 ms 4448 KB Output is correct
99 Correct 1 ms 4704 KB Output is correct
100 Correct 1 ms 4436 KB Output is correct
101 Correct 1 ms 4436 KB Output is correct
102 Correct 1 ms 4684 KB Output is correct
103 Correct 2 ms 4436 KB Output is correct
104 Correct 5 ms 5460 KB Output is correct
105 Correct 10 ms 7352 KB Output is correct
106 Correct 1 ms 4860 KB Output is correct
107 Correct 19 ms 9620 KB Output is correct
108 Correct 26 ms 13140 KB Output is correct
109 Correct 2 ms 4692 KB Output is correct
110 Correct 33 ms 13240 KB Output is correct
111 Correct 37 ms 14924 KB Output is correct
112 Correct 1 ms 4692 KB Output is correct
113 Correct 56 ms 24940 KB Output is correct
114 Correct 14 ms 6992 KB Output is correct
115 Correct 14 ms 7072 KB Output is correct
116 Correct 14 ms 6992 KB Output is correct
117 Correct 15 ms 7132 KB Output is correct
118 Correct 15 ms 6992 KB Output is correct
119 Correct 15 ms 7380 KB Output is correct
120 Correct 15 ms 7140 KB Output is correct
121 Correct 14 ms 7004 KB Output is correct
122 Correct 14 ms 6992 KB Output is correct
123 Correct 17 ms 7212 KB Output is correct
124 Correct 1 ms 4600 KB Output is correct
125 Correct 4 ms 5324 KB Output is correct
126 Correct 5 ms 5324 KB Output is correct
127 Correct 4 ms 5324 KB Output is correct
128 Correct 4 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 5324 KB Output is correct
132 Correct 8 ms 5324 KB Output is correct
133 Incorrect 1 ms 4432 KB Output isn't correct
134 Halted 0 ms 0 KB -