Submission #290728

# Submission time Handle Problem Language Result Execution time Memory
290728 2020-09-04T11:31:55 Z TadijaSebez Swapping Cities (APIO20_swap) C++11
100 / 100
449 ms 26604 KB
#include "swap.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

const int N=100050;
const int inf=1e9+7;
int myc[N],dst[N],tme[N],deg[N];
vector<int> cmp[N],my[N];
void mrg(int u,int v,int w){
	deg[u]++;deg[v]++;
	if(myc[u]==myc[v]){
		int c=myc[u];
		tme[c]=min(tme[c],w);
	}else{
		int c1=myc[u],c2=myc[v];
		if(cmp[c1].size()>cmp[c2].size())swap(c1,c2);
		tme[c2]=min(tme[c2],max(tme[c1],w));
		dst[c1]=w;
		if(deg[u]>2||deg[v]>2)tme[c2]=min(tme[c2],w);
		for(int i:cmp[c1]){
			myc[i]=c2;
			my[i].pb(c2);
			cmp[c2].pb(i);
		}
		cmp[c1].clear();
	}
}

void init(int n,int m,vector<int> u,vector<int> v,vector<int> w){
	vector<int> idx;
	for(int i=0;i<m;i++)idx.pb(i);
	sort(idx.begin(),idx.end(),[&](int i,int j){return w[i]<w[j];});
	for(int i=0;i<n;i++){
		myc[i]=i;
		cmp[i]={i};
		dst[i]=inf;
		tme[i]=inf;
		my[i].pb(i);
	}
	for(int i:idx){
		mrg(u[i],v[i],w[i]);
	}
}

int getMinimumFuelCapacity(int x,int y){
	int i=0,j=0,mn=0;
	while(i<my[x].size()&&j<my[y].size()&&my[x][i]!=my[y][j]){
		if(dst[my[x][i]]<dst[my[y][j]])mn=max(mn,dst[my[x][i]]),i++;
		else mn=max(mn,dst[my[y][j]]),j++;
	}
	if(i==my[x].size()||j==my[y].size())return -1;
	int ans=inf;
	while(i<my[x].size()){
		ans=min(ans,max(tme[my[x][i]],mn));
		mn=dst[my[x][i]];
		assert(j<my[y].size()&&my[x][i]==my[y][j]);
		i++;j++;
	}
	return ans==inf?-1:ans;
}

Compilation message

swap.cpp: In function 'int getMinimumFuelCapacity(int, int)':
swap.cpp:48:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  while(i<my[x].size()&&j<my[y].size()&&my[x][i]!=my[y][j]){
      |        ~^~~~~~~~~~~~~
swap.cpp:48:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |  while(i<my[x].size()&&j<my[y].size()&&my[x][i]!=my[y][j]){
      |                        ~^~~~~~~~~~~~~
swap.cpp:52:6: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  if(i==my[x].size()||j==my[y].size())return -1;
      |     ~^~~~~~~~~~~~~~
swap.cpp:52:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  if(i==my[x].size()||j==my[y].size())return -1;
      |                      ~^~~~~~~~~~~~~~
swap.cpp:54:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |  while(i<my[x].size()){
      |        ~^~~~~~~~~~~~~
In file included from /usr/include/c++/9/cassert:44,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from swap.cpp:2:
swap.cpp:57:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |   assert(j<my[y].size()&&my[x][i]==my[y][j]);
      |          ~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 162 ms 18544 KB Output is correct
10 Correct 225 ms 21220 KB Output is correct
11 Correct 207 ms 20976 KB Output is correct
12 Correct 226 ms 21872 KB Output is correct
13 Correct 137 ms 16880 KB Output is correct
14 Correct 185 ms 18672 KB Output is correct
15 Correct 346 ms 23268 KB Output is correct
16 Correct 340 ms 22512 KB Output is correct
17 Correct 355 ms 23792 KB Output is correct
18 Correct 246 ms 18288 KB Output is correct
19 Correct 102 ms 11000 KB Output is correct
20 Correct 342 ms 24176 KB Output is correct
21 Correct 336 ms 23868 KB Output is correct
22 Correct 368 ms 25040 KB Output is correct
23 Correct 261 ms 19132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 217 ms 18208 KB Output is correct
4 Correct 217 ms 18512 KB Output is correct
5 Correct 225 ms 18704 KB Output is correct
6 Correct 212 ms 18512 KB Output is correct
7 Correct 226 ms 18692 KB Output is correct
8 Correct 210 ms 18220 KB Output is correct
9 Correct 214 ms 18540 KB Output is correct
10 Correct 217 ms 18240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 5 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 4 ms 5120 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 4 ms 5120 KB Output is correct
13 Correct 5 ms 5120 KB Output is correct
14 Correct 4 ms 5120 KB Output is correct
15 Correct 5 ms 5120 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 5 ms 5120 KB Output is correct
18 Correct 5 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 5 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 4 ms 5120 KB Output is correct
23 Correct 4 ms 5120 KB Output is correct
24 Correct 5 ms 5120 KB Output is correct
25 Correct 5 ms 5120 KB Output is correct
26 Correct 5 ms 5248 KB Output is correct
27 Correct 4 ms 5120 KB Output is correct
28 Correct 5 ms 5120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 5 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 162 ms 18544 KB Output is correct
11 Correct 225 ms 21220 KB Output is correct
12 Correct 207 ms 20976 KB Output is correct
13 Correct 226 ms 21872 KB Output is correct
14 Correct 137 ms 16880 KB Output is correct
15 Correct 4 ms 5120 KB Output is correct
16 Correct 4 ms 5120 KB Output is correct
17 Correct 4 ms 5120 KB Output is correct
18 Correct 5 ms 5120 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 5 ms 5120 KB Output is correct
21 Correct 4 ms 5120 KB Output is correct
22 Correct 5 ms 5120 KB Output is correct
23 Correct 5 ms 5120 KB Output is correct
24 Correct 18 ms 6912 KB Output is correct
25 Correct 234 ms 21872 KB Output is correct
26 Correct 216 ms 21616 KB Output is correct
27 Correct 212 ms 21232 KB Output is correct
28 Correct 204 ms 20592 KB Output is correct
29 Correct 206 ms 20464 KB Output is correct
30 Correct 181 ms 18800 KB Output is correct
31 Correct 227 ms 22128 KB Output is correct
32 Correct 222 ms 22128 KB Output is correct
33 Correct 131 ms 16496 KB Output is correct
34 Correct 205 ms 20208 KB Output is correct
35 Correct 4 ms 5120 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 4 ms 5120 KB Output is correct
38 Correct 4 ms 5120 KB Output is correct
39 Correct 4 ms 5120 KB Output is correct
40 Correct 5 ms 5120 KB Output is correct
41 Correct 5 ms 5120 KB Output is correct
42 Correct 5 ms 5248 KB Output is correct
43 Correct 4 ms 5120 KB Output is correct
44 Correct 5 ms 5120 KB Output is correct
45 Correct 167 ms 16620 KB Output is correct
46 Correct 225 ms 21616 KB Output is correct
47 Correct 177 ms 19056 KB Output is correct
48 Correct 153 ms 17136 KB Output is correct
49 Correct 88 ms 9840 KB Output is correct
50 Correct 73 ms 9076 KB Output is correct
51 Correct 133 ms 14640 KB Output is correct
52 Correct 261 ms 22756 KB Output is correct
53 Correct 234 ms 20076 KB Output is correct
54 Correct 286 ms 24940 KB Output is correct
55 Correct 138 ms 16496 KB Output is correct
56 Correct 216 ms 19308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 4 ms 4992 KB Output is correct
4 Correct 4 ms 5120 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 5 ms 5120 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 162 ms 18544 KB Output is correct
10 Correct 225 ms 21220 KB Output is correct
11 Correct 207 ms 20976 KB Output is correct
12 Correct 226 ms 21872 KB Output is correct
13 Correct 137 ms 16880 KB Output is correct
14 Correct 185 ms 18672 KB Output is correct
15 Correct 346 ms 23268 KB Output is correct
16 Correct 340 ms 22512 KB Output is correct
17 Correct 355 ms 23792 KB Output is correct
18 Correct 246 ms 18288 KB Output is correct
19 Correct 217 ms 18208 KB Output is correct
20 Correct 217 ms 18512 KB Output is correct
21 Correct 225 ms 18704 KB Output is correct
22 Correct 212 ms 18512 KB Output is correct
23 Correct 226 ms 18692 KB Output is correct
24 Correct 210 ms 18220 KB Output is correct
25 Correct 214 ms 18540 KB Output is correct
26 Correct 217 ms 18240 KB Output is correct
27 Correct 4 ms 5120 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 4 ms 5120 KB Output is correct
30 Correct 5 ms 5120 KB Output is correct
31 Correct 4 ms 5120 KB Output is correct
32 Correct 5 ms 5120 KB Output is correct
33 Correct 4 ms 5120 KB Output is correct
34 Correct 5 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 18 ms 6912 KB Output is correct
37 Correct 234 ms 21872 KB Output is correct
38 Correct 216 ms 21616 KB Output is correct
39 Correct 212 ms 21232 KB Output is correct
40 Correct 204 ms 20592 KB Output is correct
41 Correct 206 ms 20464 KB Output is correct
42 Correct 181 ms 18800 KB Output is correct
43 Correct 227 ms 22128 KB Output is correct
44 Correct 222 ms 22128 KB Output is correct
45 Correct 131 ms 16496 KB Output is correct
46 Correct 205 ms 20208 KB Output is correct
47 Correct 26 ms 7292 KB Output is correct
48 Correct 340 ms 24452 KB Output is correct
49 Correct 342 ms 23632 KB Output is correct
50 Correct 343 ms 23540 KB Output is correct
51 Correct 338 ms 23264 KB Output is correct
52 Correct 318 ms 21936 KB Output is correct
53 Correct 234 ms 18404 KB Output is correct
54 Correct 358 ms 24848 KB Output is correct
55 Correct 356 ms 24532 KB Output is correct
56 Correct 247 ms 18724 KB Output is correct
57 Correct 331 ms 22864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5120 KB Output is correct
2 Correct 4 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 4 ms 4992 KB Output is correct
5 Correct 4 ms 5120 KB Output is correct
6 Correct 4 ms 5120 KB Output is correct
7 Correct 4 ms 5120 KB Output is correct
8 Correct 5 ms 5120 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 162 ms 18544 KB Output is correct
11 Correct 225 ms 21220 KB Output is correct
12 Correct 207 ms 20976 KB Output is correct
13 Correct 226 ms 21872 KB Output is correct
14 Correct 137 ms 16880 KB Output is correct
15 Correct 185 ms 18672 KB Output is correct
16 Correct 346 ms 23268 KB Output is correct
17 Correct 340 ms 22512 KB Output is correct
18 Correct 355 ms 23792 KB Output is correct
19 Correct 246 ms 18288 KB Output is correct
20 Correct 217 ms 18208 KB Output is correct
21 Correct 217 ms 18512 KB Output is correct
22 Correct 225 ms 18704 KB Output is correct
23 Correct 212 ms 18512 KB Output is correct
24 Correct 226 ms 18692 KB Output is correct
25 Correct 210 ms 18220 KB Output is correct
26 Correct 214 ms 18540 KB Output is correct
27 Correct 217 ms 18240 KB Output is correct
28 Correct 4 ms 5120 KB Output is correct
29 Correct 4 ms 5120 KB Output is correct
30 Correct 4 ms 5120 KB Output is correct
31 Correct 5 ms 5120 KB Output is correct
32 Correct 4 ms 5120 KB Output is correct
33 Correct 5 ms 5120 KB Output is correct
34 Correct 4 ms 5120 KB Output is correct
35 Correct 5 ms 5120 KB Output is correct
36 Correct 5 ms 5120 KB Output is correct
37 Correct 18 ms 6912 KB Output is correct
38 Correct 234 ms 21872 KB Output is correct
39 Correct 216 ms 21616 KB Output is correct
40 Correct 212 ms 21232 KB Output is correct
41 Correct 204 ms 20592 KB Output is correct
42 Correct 206 ms 20464 KB Output is correct
43 Correct 181 ms 18800 KB Output is correct
44 Correct 227 ms 22128 KB Output is correct
45 Correct 222 ms 22128 KB Output is correct
46 Correct 131 ms 16496 KB Output is correct
47 Correct 205 ms 20208 KB Output is correct
48 Correct 26 ms 7292 KB Output is correct
49 Correct 340 ms 24452 KB Output is correct
50 Correct 342 ms 23632 KB Output is correct
51 Correct 343 ms 23540 KB Output is correct
52 Correct 338 ms 23264 KB Output is correct
53 Correct 318 ms 21936 KB Output is correct
54 Correct 234 ms 18404 KB Output is correct
55 Correct 358 ms 24848 KB Output is correct
56 Correct 356 ms 24532 KB Output is correct
57 Correct 247 ms 18724 KB Output is correct
58 Correct 331 ms 22864 KB Output is correct
59 Correct 102 ms 11000 KB Output is correct
60 Correct 342 ms 24176 KB Output is correct
61 Correct 336 ms 23868 KB Output is correct
62 Correct 368 ms 25040 KB Output is correct
63 Correct 261 ms 19132 KB Output is correct
64 Correct 4 ms 5120 KB Output is correct
65 Correct 5 ms 5120 KB Output is correct
66 Correct 4 ms 5120 KB Output is correct
67 Correct 4 ms 5120 KB Output is correct
68 Correct 4 ms 5120 KB Output is correct
69 Correct 5 ms 5120 KB Output is correct
70 Correct 5 ms 5120 KB Output is correct
71 Correct 5 ms 5248 KB Output is correct
72 Correct 4 ms 5120 KB Output is correct
73 Correct 5 ms 5120 KB Output is correct
74 Correct 167 ms 16620 KB Output is correct
75 Correct 225 ms 21616 KB Output is correct
76 Correct 177 ms 19056 KB Output is correct
77 Correct 153 ms 17136 KB Output is correct
78 Correct 88 ms 9840 KB Output is correct
79 Correct 73 ms 9076 KB Output is correct
80 Correct 133 ms 14640 KB Output is correct
81 Correct 261 ms 22756 KB Output is correct
82 Correct 234 ms 20076 KB Output is correct
83 Correct 286 ms 24940 KB Output is correct
84 Correct 138 ms 16496 KB Output is correct
85 Correct 216 ms 19308 KB Output is correct
86 Correct 74 ms 9716 KB Output is correct
87 Correct 345 ms 23248 KB Output is correct
88 Correct 345 ms 23632 KB Output is correct
89 Correct 256 ms 18800 KB Output is correct
90 Correct 179 ms 11760 KB Output is correct
91 Correct 178 ms 12104 KB Output is correct
92 Correct 233 ms 16876 KB Output is correct
93 Correct 362 ms 23860 KB Output is correct
94 Correct 363 ms 21908 KB Output is correct
95 Correct 449 ms 26604 KB Output is correct
96 Correct 246 ms 19024 KB Output is correct
97 Correct 315 ms 20688 KB Output is correct