Submission #960911

# Submission time Handle Problem Language Result Execution time Memory
960911 2024-04-11T08:15:07 Z pcc Cities (BOI16_cities) C++17
0 / 100
143 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;
int tar[6];
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]);}

void check(vector<pair<pii,int>> e){
	sort(e.begin(),e.end(),[](pair<pii,int> a,pair<pii,int> b){return a.sc<b.sc;});
	init();
	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)];
	}
	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--;
		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 1 ms 344 KB Output is correct
2 Incorrect 143 ms 440 KB Output isn't correct
3 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 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 -