Submission #960916

# Submission time Handle Problem Language Result Execution time Memory
960916 2024-04-11T08:28:43 Z pcc Cities (BOI16_cities) C++17
22 / 100
142 ms 604 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fs first
#define sc second
#define tlll tuple<ll,ll,ll>

const int mxn = 49;

int N,M,K;
pair<pii,int> edges[mxn];
ll ans = 1e18;
int dsu[mxn];

void init(){
	for(int i = 0;i<=N;i++)dsu[i] = i;
	return;
}
int root(int k){return k == dsu[k]?k:dsu[k] = root(dsu[k]);}
int tar[6];

void check(vector<pair<pii,int>> e){
	init();
	sort(e.begin(),e.end(),[](pair<pii,int> a,pair<pii,int> b){return a.sc<b.sc;});
	ll ts = 0;
	for(auto &[a,w]:e){
		if(root(a.fs) != root(a.sc))ts += w;
		dsu[root(a.fs)] = dsu[root(a.sc)];
	}
	for(int i = 0;i<K;i++){
		if(root(tar[0]) != root(tar[i]))return;
	}
	ans = min(ans,ts);
	return;
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>K>>M;
	int mask = 0;
	for(int i = 0;i<K;i++){
		int t;
		cin>>t;
		t--;
		tar[i] = t;
		mask|=1<<t;
	}
	for(int i = 0;i<M;i++){
		auto &[a,b] = edges[i];
		cin>>a.fs>>a.sc>>b;
		a.fs--,a.sc--;
	}
	for(int i = 1;i<(1<<N);i++){
		if((i&mask) != mask)continue;
		vector<pair<pii,int>> used;
		for(int j = 0;j<M;j++){
			auto [a,w] = edges[j];
			if((i&(1<<a.fs))&&(i&(1<<a.sc)))used.push_back(edges[j]);
		}
		check(used);
	}
	cout<<ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 352 KB Output is correct
2 Correct 142 ms 436 KB Output is correct
3 Correct 80 ms 348 KB Output is correct
4 Correct 48 ms 348 KB Output is correct
5 Correct 26 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 600 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -