답안 #253403

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253403 2020-07-28T00:48:03 Z super_j6 Museum (CEOI17_museum) C++14
20 / 100
153 ms 1144 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
#define endl '\n'
#define ll long long
#define pi pair<int, int>
#define f first
#define s second

const int mxn = 10000;
int n, k, x;
int p[mxn], vis[mxn];
vector<pi> g[mxn];
priority_queue<pi, vector<pi>, greater<pi>> pq;

void dfs(int c){
	for(pi i : g[c]){
		if(i.f == p[c]) continue;
		p[i.f] = c;
		dfs(i.f);
	}
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k >> x;
	x--;
	
	for(int i = 0; i < n - 1; i++){
		int u, v, w;
		cin >> u >> v >> w;
		u--, v--;
		g[u].push_back({v, w});
		g[v].push_back({u, w});
	}
	
	p[x] = -1;
	dfs(x);
	
	
	int ret = 0x3f3f3f3f;
	for(int i = 0; i < n; i++){
		int cnt = k, cur = 0;
		memset(vis, 0, sizeof(vis));
		while(!pq.empty()) pq.pop();
		for(int j = i; ~j; j = p[j]){
			cnt--, vis[j] = 1;
			for(pi l : g[j]){
				if(l.f == p[j]) cur += l.s;
				else if(!vis[l.f]) pq.push({2 * l.s, l.f});
			}
		}
		while(cnt > 0){
			cur += pq.top().f;
			int c = pq.top().s;
			pq.pop();
			cnt--, vis[c] = 1;
			for(pi j : g[c]){
				if(!vis[j.f]) pq.push({2 * j.s, j.f});
			}
		}
		ret = min(ret, cur);
	}
	
	cout << ret << endl;

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 153 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 153 ms 1144 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 640 KB Output is correct
2 Correct 1 ms 640 KB Output is correct
3 Correct 1 ms 640 KB Output is correct
4 Correct 1 ms 640 KB Output is correct
5 Correct 1 ms 640 KB Output is correct
6 Incorrect 153 ms 1144 KB Output isn't correct
7 Halted 0 ms 0 KB -