답안 #107117

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
107117 2019-04-22T05:07:59 Z SOIVIEONE Cities (BOI16_cities) C++14
0 / 100
1064 ms 70104 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) (x.begin(), x.end())
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 1222222

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

const ld pi = 2 * acos(0.0);
template<class T> bool umin(T& a, T b){if(a>b){a=b;return 1;}return 0;}
template<class T> bool umax(T& a, T b){if(a<b){a=b;return 1;}return 0;}
template<class T, class TT> bool pal(T a, TT n){int k=0;for(int i=0;i<=n/2;i++){if(a[i]!=a[n-i-1]){k=1;break;}}return k?0:1;}

//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
ll p[N], sz[N], c[N], o[N], used[N];
vll v[N];
void dfs(int u)
{
	used[u] = 1;
	for(auto it : v[u])
	{
		if(used[it] == 0)
		{
			o[it] = u;
			dfs(it);
		}
	}
}

ll find(ll x)
{
	return (p[x] == x ? x : p[x] = find(p[x]));
}

int main()
{
	int n, m, k;
	cin >> n >> k >> m;
	for(int i = 1; i <= k; i ++)
		cin >> c[i];
	vector<pair<ll, pll> > e;
	map<pll, ll> mp;
	for(int i = 1; i <= m; i ++)
	{
		ll x, y, w;
		cin >> x >> y >> w;
		mp[M(x, y)] = mp[M(y, x)] = w;
		e.pb(M(w, M(x, y)));
	}
	for(int i = 1; i <= n; i ++)
		p[i] = i;
	for(int i = 1; i <= k; i ++)
		sz[c[i]] = 1;
	sort all(e);
	for(auto it : e)
	{
		ll x = it.S.F, y = it.S.S, w = it.F;
		x = find(x);
		y = find(y);
		if(x != y)
		{
			if(sz[y] > sz[x])
				swap(x, y);
			sz[x] += sz[y];
			p[y] = x;
			v[it.S.F].pb(it.S.S);
			v[it.S.S].pb(it.S.F);
			if(sz[x] == k)
				break;
		}
	}
	dfs(c[1]);
	set<pll> foo;
	for(int i = 2; i <= k; i ++)
	{
		ll cur = c[i];
		while(cur != c[1])
		{
			ll fo = cur, ho = o[cur];
			if(ho > fo)
				swap(fo,ho);
			foo.insert(M(fo, ho));
			cur = o[cur];
		}
	}
	ll ans = 0;
	for(auto it : foo)
		ans += mp[it];
	cout << ans;
	return 0;
	//ios::sync_with_stdio(false);
	//cin.tie(0);
}

Compilation message

cities.cpp: In function 'int main()':
cities.cpp:75:30: warning: unused variable 'w' [-Wunused-variable]
   ll x = it.S.F, y = it.S.S, w = it.F;
                              ^
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 29048 KB Output is correct
2 Correct 31 ms 29048 KB Output is correct
3 Incorrect 58 ms 29176 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1064 ms 69736 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 35 ms 29536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1046 ms 70104 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1033 ms 69300 KB Output isn't correct
2 Halted 0 ms 0 KB -