답안 #308104

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
308104 2020-09-30T03:57:00 Z fefe 자매 도시 (APIO20_swap) C++17
13 / 100
376 ms 20436 KB
#include "swap.h"

#include <vector>
#include<bits/stdc++.h>
using namespace std;
const int MAX_N = 100005;

struct EDGE{
	int x,y;
	int v;
	EDGE(int _x, int _y, int _v): x(_x), y(_y), v(_v){}
	bool operator < (const EDGE d){
		if(v == d.v){
			return x < d.x;
		}
		return v < d.v;
	}
};
vector<EDGE> lst, cnt[MAX_N];
int par[MAX_N], height[MAX_N];
int deg[MAX_N];
int val[MAX_N];
int m;

int find_par(int x, int max_val){
	if(val[x] > max_val)	return x;
	return (x == par[x]) ? (x) : (par[x] = find_par(par[x], max_val));
}
void merge(int x, int y, int v){
	deg[x]++;
	deg[y]++;
	x = find_par(x, v);
	y = find_par(y, v);
	if(x == y){
		EDGE p = cnt[x].back();
		p.y++;
		p.v = v;
		if(deg[x] == 3 || deg[y] == 3)	p.y++;
		cnt[x].push_back(p);
		return;
	}
	if(height[y] > height[x]){
		swap(x,y);
	}
	par[y] = x;
	val[y] = v;
	height[x] += height[x] == height[y];

	EDGE p = EDGE(cnt[x].back().x + cnt[y].back().x, cnt[x].back().y + cnt[y].back().y + 1, v);
	if(deg[x] == 3 || deg[y] == 3)	p.y++;
	cnt[x].push_back(p);
}
void init(int N, int M, std::vector<int> U, std::vector<int> V, std::vector<int> W) {
	m = M;
	for(int i=0;i<M;i++){
		lst.push_back(EDGE(U[i], V[i], W[i]));
	}
	
	for(int i=0;i<N;i++){
		par[i] = i;
		height[i] = 1;
		val[i] = -1;
		cnt[i].push_back(EDGE(1,0,-1));
	}

	sort(lst.begin(), lst.end(), [&](const EDGE x, const EDGE y){
		return x.v < y.v;
	});
	
	int i = 0;
	for(EDGE p:lst){
		merge(p.x, p.y, i);
		i++;
	}
}

bool is_ok(int max_val, int x, int y){
	x = find_par(x, max_val);
	y = find_par(y, max_val);
	
	if(x != y)	return false;
	
	int idx = lower_bound(cnt[x].begin(), cnt[x].end(), EDGE(MAX_N, MAX_N, max_val)) - cnt[x].begin() - 1;

	return cnt[x][idx].x <= cnt[x][idx].y;
}

int getMinimumFuelCapacity(int X, int Y) {
	int l = 0, r = m-1;
	while(l < r){
		int mid = (l + r) >> 1;
		if(is_ok(mid, X, Y)){
			r = mid;
		}else{
			l = mid + 1;
		}
	}

	return is_ok(l, X, Y) ? lst[l].v : -1;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 75 ms 10728 KB Output is correct
10 Correct 95 ms 12524 KB Output is correct
11 Correct 93 ms 12396 KB Output is correct
12 Correct 95 ms 12908 KB Output is correct
13 Correct 85 ms 13296 KB Output is correct
14 Correct 86 ms 11068 KB Output is correct
15 Correct 263 ms 14584 KB Output is correct
16 Correct 252 ms 14200 KB Output is correct
17 Correct 265 ms 14676 KB Output is correct
18 Correct 316 ms 14516 KB Output is correct
19 Correct 134 ms 7992 KB Output is correct
20 Correct 252 ms 19820 KB Output is correct
21 Correct 259 ms 19752 KB Output is correct
22 Correct 268 ms 20436 KB Output is correct
23 Correct 321 ms 20176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 357 ms 14604 KB Output is correct
4 Correct 357 ms 18768 KB Output is correct
5 Correct 376 ms 19076 KB Output is correct
6 Correct 355 ms 18780 KB Output is correct
7 Correct 375 ms 19176 KB Output is correct
8 Correct 363 ms 18456 KB Output is correct
9 Correct 375 ms 18664 KB Output is correct
10 Correct 370 ms 18472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Incorrect 3 ms 2816 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 75 ms 10728 KB Output is correct
11 Correct 95 ms 12524 KB Output is correct
12 Correct 93 ms 12396 KB Output is correct
13 Correct 95 ms 12908 KB Output is correct
14 Correct 85 ms 13296 KB Output is correct
15 Incorrect 3 ms 2816 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 3 ms 2816 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 2 ms 2816 KB Output is correct
8 Correct 3 ms 2816 KB Output is correct
9 Correct 75 ms 10728 KB Output is correct
10 Correct 95 ms 12524 KB Output is correct
11 Correct 93 ms 12396 KB Output is correct
12 Correct 95 ms 12908 KB Output is correct
13 Correct 85 ms 13296 KB Output is correct
14 Correct 86 ms 11068 KB Output is correct
15 Correct 263 ms 14584 KB Output is correct
16 Correct 252 ms 14200 KB Output is correct
17 Correct 265 ms 14676 KB Output is correct
18 Correct 316 ms 14516 KB Output is correct
19 Correct 357 ms 14604 KB Output is correct
20 Correct 357 ms 18768 KB Output is correct
21 Correct 376 ms 19076 KB Output is correct
22 Correct 355 ms 18780 KB Output is correct
23 Correct 375 ms 19176 KB Output is correct
24 Correct 363 ms 18456 KB Output is correct
25 Correct 375 ms 18664 KB Output is correct
26 Correct 370 ms 18472 KB Output is correct
27 Incorrect 3 ms 2816 KB Output isn't correct
28 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2688 KB Output is correct
2 Correct 2 ms 2688 KB Output is correct
3 Correct 2 ms 2688 KB Output is correct
4 Correct 2 ms 2688 KB Output is correct
5 Correct 2 ms 2688 KB Output is correct
6 Correct 3 ms 2816 KB Output is correct
7 Correct 3 ms 2816 KB Output is correct
8 Correct 2 ms 2816 KB Output is correct
9 Correct 3 ms 2816 KB Output is correct
10 Correct 75 ms 10728 KB Output is correct
11 Correct 95 ms 12524 KB Output is correct
12 Correct 93 ms 12396 KB Output is correct
13 Correct 95 ms 12908 KB Output is correct
14 Correct 85 ms 13296 KB Output is correct
15 Correct 86 ms 11068 KB Output is correct
16 Correct 263 ms 14584 KB Output is correct
17 Correct 252 ms 14200 KB Output is correct
18 Correct 265 ms 14676 KB Output is correct
19 Correct 316 ms 14516 KB Output is correct
20 Correct 357 ms 14604 KB Output is correct
21 Correct 357 ms 18768 KB Output is correct
22 Correct 376 ms 19076 KB Output is correct
23 Correct 355 ms 18780 KB Output is correct
24 Correct 375 ms 19176 KB Output is correct
25 Correct 363 ms 18456 KB Output is correct
26 Correct 375 ms 18664 KB Output is correct
27 Correct 370 ms 18472 KB Output is correct
28 Incorrect 3 ms 2816 KB Output isn't correct
29 Halted 0 ms 0 KB -