답안 #290726

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
290726 2020-09-04T11:15:06 Z TadijaSebez 자매 도시 (APIO20_swap) C++11
13 / 100
365 ms 25036 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],tme[c1]);
		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,tme[my[x][i]]);
		assert(j<my[y].size()&&my[x][i]==my[y][j]);
		i++;j++;
	}
	ans=max(ans,mn);
	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:56:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   assert(j<my[y].size()&&my[x][i]==my[y][j]);
      |          ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 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 5248 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 169 ms 18544 KB Output is correct
10 Correct 215 ms 21104 KB Output is correct
11 Correct 212 ms 21104 KB Output is correct
12 Correct 234 ms 21992 KB Output is correct
13 Correct 141 ms 16880 KB Output is correct
14 Correct 181 ms 18544 KB Output is correct
15 Correct 346 ms 23408 KB Output is correct
16 Correct 340 ms 22512 KB Output is correct
17 Correct 365 ms 23920 KB Output is correct
18 Correct 252 ms 18100 KB Output is correct
19 Correct 102 ms 11000 KB Output is correct
20 Correct 346 ms 24136 KB Output is correct
21 Correct 345 ms 23872 KB Output is correct
22 Correct 361 ms 25036 KB Output is correct
23 Correct 246 ms 19264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 208 ms 18144 KB Output is correct
4 Correct 220 ms 18596 KB Output is correct
5 Correct 214 ms 18576 KB Output is correct
6 Correct 221 ms 18508 KB Output is correct
7 Correct 215 ms 18672 KB Output is correct
8 Correct 207 ms 18224 KB Output is correct
9 Correct 211 ms 18460 KB Output is correct
10 Correct 208 ms 18112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 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 5248 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 Incorrect 4 ms 5120 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 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 5248 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 169 ms 18544 KB Output is correct
11 Correct 215 ms 21104 KB Output is correct
12 Correct 212 ms 21104 KB Output is correct
13 Correct 234 ms 21992 KB Output is correct
14 Correct 141 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 Incorrect 4 ms 5120 KB Output isn't correct
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4992 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 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 5248 KB Output is correct
8 Correct 4 ms 5120 KB Output is correct
9 Correct 169 ms 18544 KB Output is correct
10 Correct 215 ms 21104 KB Output is correct
11 Correct 212 ms 21104 KB Output is correct
12 Correct 234 ms 21992 KB Output is correct
13 Correct 141 ms 16880 KB Output is correct
14 Correct 181 ms 18544 KB Output is correct
15 Correct 346 ms 23408 KB Output is correct
16 Correct 340 ms 22512 KB Output is correct
17 Correct 365 ms 23920 KB Output is correct
18 Correct 252 ms 18100 KB Output is correct
19 Correct 208 ms 18144 KB Output is correct
20 Correct 220 ms 18596 KB Output is correct
21 Correct 214 ms 18576 KB Output is correct
22 Correct 221 ms 18508 KB Output is correct
23 Correct 215 ms 18672 KB Output is correct
24 Correct 207 ms 18224 KB Output is correct
25 Correct 211 ms 18460 KB Output is correct
26 Correct 208 ms 18112 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 Incorrect 4 ms 5120 KB Output isn't correct
33 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 5120 KB Output is correct
2 Correct 3 ms 4992 KB Output is correct
3 Correct 3 ms 4992 KB Output is correct
4 Correct 3 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 5248 KB Output is correct
9 Correct 4 ms 5120 KB Output is correct
10 Correct 169 ms 18544 KB Output is correct
11 Correct 215 ms 21104 KB Output is correct
12 Correct 212 ms 21104 KB Output is correct
13 Correct 234 ms 21992 KB Output is correct
14 Correct 141 ms 16880 KB Output is correct
15 Correct 181 ms 18544 KB Output is correct
16 Correct 346 ms 23408 KB Output is correct
17 Correct 340 ms 22512 KB Output is correct
18 Correct 365 ms 23920 KB Output is correct
19 Correct 252 ms 18100 KB Output is correct
20 Correct 208 ms 18144 KB Output is correct
21 Correct 220 ms 18596 KB Output is correct
22 Correct 214 ms 18576 KB Output is correct
23 Correct 221 ms 18508 KB Output is correct
24 Correct 215 ms 18672 KB Output is correct
25 Correct 207 ms 18224 KB Output is correct
26 Correct 211 ms 18460 KB Output is correct
27 Correct 208 ms 18112 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 Incorrect 4 ms 5120 KB Output isn't correct
34 Halted 0 ms 0 KB -