답안 #1100964

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1100964 2024-10-15T05:42:50 Z alexander707070 꿈 (IOI13_dreaming) C++14
47 / 100
54 ms 24708 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 1/0;
		
		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++){
      |              ~^~~~~~~~~~~~
dreaming.cpp: In function 'int travelTime(int, int, int, int*, int*, int*)':
dreaming.cpp:82:11: warning: division by zero [-Wdiv-by-zero]
   82 |   return 1/0;
      |          ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 16200 KB Output is correct
2 Correct 39 ms 15688 KB Output is correct
3 Correct 28 ms 15440 KB Output is correct
4 Correct 7 ms 6224 KB Output is correct
5 Correct 5 ms 5488 KB Output is correct
6 Correct 12 ms 7036 KB Output is correct
7 Correct 2 ms 4688 KB Output is correct
8 Correct 20 ms 9288 KB Output is correct
9 Correct 28 ms 12872 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
11 Correct 35 ms 12604 KB Output is correct
12 Correct 40 ms 14480 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4480 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4600 KB Output is correct
9 Correct 1 ms 4432 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 4432 KB Output is correct
16 Correct 1 ms 4688 KB Output is correct
17 Correct 2 ms 4432 KB Output is correct
18 Correct 2 ms 4684 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 2 ms 4432 KB Output is correct
21 Correct 2 ms 4432 KB Output is correct
22 Correct 2 ms 4432 KB Output is correct
23 Correct 2 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 16200 KB Output is correct
2 Correct 39 ms 15688 KB Output is correct
3 Correct 28 ms 15440 KB Output is correct
4 Correct 7 ms 6224 KB Output is correct
5 Correct 5 ms 5488 KB Output is correct
6 Correct 12 ms 7036 KB Output is correct
7 Correct 2 ms 4688 KB Output is correct
8 Correct 20 ms 9288 KB Output is correct
9 Correct 28 ms 12872 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
11 Correct 35 ms 12604 KB Output is correct
12 Correct 40 ms 14480 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 2 ms 4480 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 2 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4600 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 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 4432 KB Output is correct
29 Correct 1 ms 4688 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4684 KB Output is correct
32 Correct 1 ms 4432 KB Output is correct
33 Correct 2 ms 4432 KB Output is correct
34 Correct 2 ms 4432 KB Output is correct
35 Correct 2 ms 4432 KB Output is correct
36 Correct 2 ms 4432 KB Output is correct
37 Correct 1 ms 4432 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 36 ms 16224 KB Output is correct
40 Correct 36 ms 15696 KB Output is correct
41 Correct 31 ms 15440 KB Output is correct
42 Correct 7 ms 6224 KB Output is correct
43 Correct 1 ms 4432 KB Output is correct
44 Correct 1 ms 4540 KB Output is correct
45 Correct 1 ms 4432 KB Output is correct
46 Correct 2 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 4432 KB Output is correct
55 Correct 1 ms 4432 KB Output is correct
56 Correct 1 ms 4600 KB Output is correct
57 Correct 42 ms 8672 KB Output is correct
58 Correct 41 ms 8776 KB Output is correct
59 Correct 44 ms 8784 KB Output is correct
60 Correct 45 ms 8748 KB Output is correct
61 Correct 40 ms 8532 KB Output is correct
62 Correct 41 ms 8680 KB Output is correct
63 Correct 40 ms 8520 KB Output is correct
64 Correct 40 ms 8516 KB Output is correct
65 Correct 39 ms 8528 KB Output is correct
66 Correct 40 ms 8528 KB Output is correct
67 Correct 44 ms 8776 KB Output is correct
68 Correct 40 ms 8784 KB Output is correct
69 Correct 40 ms 8784 KB Output is correct
70 Correct 40 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 3 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 3 ms 4688 KB Output is correct
77 Correct 2 ms 4788 KB Output is correct
78 Correct 2 ms 4688 KB Output is correct
79 Correct 3 ms 4688 KB Output is correct
80 Correct 44 ms 8776 KB Output is correct
81 Correct 40 ms 8728 KB Output is correct
82 Correct 41 ms 8528 KB Output is correct
83 Correct 40 ms 8540 KB Output is correct
84 Correct 3 ms 4688 KB Output is correct
85 Correct 2 ms 4688 KB Output is correct
86 Correct 2 ms 4688 KB Output is correct
87 Correct 3 ms 4688 KB Output is correct
88 Correct 2 ms 4688 KB Output is correct
89 Correct 2 ms 4688 KB Output is correct
90 Correct 2 ms 4688 KB Output is correct
91 Correct 3 ms 4688 KB Output is correct
92 Correct 2 ms 4688 KB Output is correct
93 Correct 2 ms 4700 KB Output is correct
94 Correct 1 ms 4432 KB Output is correct
95 Correct 1 ms 4432 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 1 ms 4444 KB Output is correct
101 Correct 1 ms 4432 KB Output is correct
102 Correct 1 ms 4432 KB Output is correct
103 Correct 1 ms 4432 KB Output is correct
104 Correct 5 ms 5456 KB Output is correct
105 Correct 11 ms 7248 KB Output is correct
106 Correct 1 ms 4688 KB Output is correct
107 Correct 19 ms 9444 KB Output is correct
108 Correct 27 ms 12880 KB Output is correct
109 Correct 1 ms 4688 KB Output is correct
110 Correct 33 ms 12568 KB Output is correct
111 Correct 37 ms 14428 KB Output is correct
112 Correct 2 ms 4688 KB Output is correct
113 Correct 54 ms 24708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 22 ms 14036 KB Execution killed with signal 4
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4480 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 2 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4600 KB Output is correct
9 Correct 1 ms 4432 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 4432 KB Output is correct
16 Correct 1 ms 4688 KB Output is correct
17 Correct 2 ms 4432 KB Output is correct
18 Correct 2 ms 4684 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 2 ms 4432 KB Output is correct
21 Correct 2 ms 4432 KB Output is correct
22 Correct 2 ms 4432 KB Output is correct
23 Correct 2 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 Runtime error 7 ms 9040 KB Execution killed with signal 4
27 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 40 ms 16200 KB Output is correct
2 Correct 39 ms 15688 KB Output is correct
3 Correct 28 ms 15440 KB Output is correct
4 Correct 7 ms 6224 KB Output is correct
5 Correct 5 ms 5488 KB Output is correct
6 Correct 12 ms 7036 KB Output is correct
7 Correct 2 ms 4688 KB Output is correct
8 Correct 20 ms 9288 KB Output is correct
9 Correct 28 ms 12872 KB Output is correct
10 Correct 2 ms 4688 KB Output is correct
11 Correct 35 ms 12604 KB Output is correct
12 Correct 40 ms 14480 KB Output is correct
13 Correct 2 ms 4688 KB Output is correct
14 Correct 2 ms 4432 KB Output is correct
15 Correct 2 ms 4432 KB Output is correct
16 Correct 2 ms 4480 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 1 ms 4432 KB Output is correct
19 Correct 2 ms 4432 KB Output is correct
20 Correct 1 ms 4432 KB Output is correct
21 Correct 1 ms 4600 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 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 4432 KB Output is correct
29 Correct 1 ms 4688 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4684 KB Output is correct
32 Correct 1 ms 4432 KB Output is correct
33 Correct 2 ms 4432 KB Output is correct
34 Correct 2 ms 4432 KB Output is correct
35 Correct 2 ms 4432 KB Output is correct
36 Correct 2 ms 4432 KB Output is correct
37 Correct 1 ms 4432 KB Output is correct
38 Correct 1 ms 4432 KB Output is correct
39 Correct 36 ms 16224 KB Output is correct
40 Correct 36 ms 15696 KB Output is correct
41 Correct 31 ms 15440 KB Output is correct
42 Correct 7 ms 6224 KB Output is correct
43 Correct 1 ms 4432 KB Output is correct
44 Correct 1 ms 4540 KB Output is correct
45 Correct 1 ms 4432 KB Output is correct
46 Correct 2 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 4432 KB Output is correct
55 Correct 1 ms 4432 KB Output is correct
56 Correct 1 ms 4600 KB Output is correct
57 Correct 42 ms 8672 KB Output is correct
58 Correct 41 ms 8776 KB Output is correct
59 Correct 44 ms 8784 KB Output is correct
60 Correct 45 ms 8748 KB Output is correct
61 Correct 40 ms 8532 KB Output is correct
62 Correct 41 ms 8680 KB Output is correct
63 Correct 40 ms 8520 KB Output is correct
64 Correct 40 ms 8516 KB Output is correct
65 Correct 39 ms 8528 KB Output is correct
66 Correct 40 ms 8528 KB Output is correct
67 Correct 44 ms 8776 KB Output is correct
68 Correct 40 ms 8784 KB Output is correct
69 Correct 40 ms 8784 KB Output is correct
70 Correct 40 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 3 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 3 ms 4688 KB Output is correct
77 Correct 2 ms 4788 KB Output is correct
78 Correct 2 ms 4688 KB Output is correct
79 Correct 3 ms 4688 KB Output is correct
80 Correct 44 ms 8776 KB Output is correct
81 Correct 40 ms 8728 KB Output is correct
82 Correct 41 ms 8528 KB Output is correct
83 Correct 40 ms 8540 KB Output is correct
84 Correct 3 ms 4688 KB Output is correct
85 Correct 2 ms 4688 KB Output is correct
86 Correct 2 ms 4688 KB Output is correct
87 Correct 3 ms 4688 KB Output is correct
88 Correct 2 ms 4688 KB Output is correct
89 Correct 2 ms 4688 KB Output is correct
90 Correct 2 ms 4688 KB Output is correct
91 Correct 3 ms 4688 KB Output is correct
92 Correct 2 ms 4688 KB Output is correct
93 Correct 2 ms 4700 KB Output is correct
94 Correct 1 ms 4432 KB Output is correct
95 Correct 1 ms 4432 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 1 ms 4444 KB Output is correct
101 Correct 1 ms 4432 KB Output is correct
102 Correct 1 ms 4432 KB Output is correct
103 Correct 1 ms 4432 KB Output is correct
104 Correct 5 ms 5456 KB Output is correct
105 Correct 11 ms 7248 KB Output is correct
106 Correct 1 ms 4688 KB Output is correct
107 Correct 19 ms 9444 KB Output is correct
108 Correct 27 ms 12880 KB Output is correct
109 Correct 1 ms 4688 KB Output is correct
110 Correct 33 ms 12568 KB Output is correct
111 Correct 37 ms 14428 KB Output is correct
112 Correct 2 ms 4688 KB Output is correct
113 Correct 54 ms 24708 KB Output is correct
114 Runtime error 22 ms 14036 KB Execution killed with signal 4
115 Halted 0 ms 0 KB -