标签:
问题描述
1 #include <bits/stdc++.h> 2 #define rep(i, a, b) for (int i = a; i <= b; i++) 3 #define drep(i, a, b) for (int i = a; i >= b; i--) 4 #define REP(i, a, b) for (int i = a; i < b; i++) 5 #define mp make_pair 6 #define pb push_back 7 #define clr(x) memset(x, 0, sizeof(x)) 8 #define xx first 9 #define yy second 10 using namespace std; 11 typedef long long i64; 12 typedef pair<int, int> pii; 13 const int inf = ~0U >> 1; 14 const i64 INF = ~0ULL >> 1; 15 //******************************** 16 const int maxn = 1005, maxm = 5005; 17 pair<int, pii> edge[maxm]; 18 int val[maxn], father[maxn], sze[maxn]; 19 inline int getfather(int x) { return father[x] == x ? x : father[x] = getfather(father[x]); } 20 int main() { 21 int n, m, k; 22 scanf("%d%d%d", &n, &m, &k); 23 rep(i, 1, n) scanf("%d", &val[i]); 24 rep(i, 1, m) scanf("%d%d%d", &edge[i].yy.xx, &edge[i].yy.yy, &edge[i].xx); 25 sort(edge + 1, edge + 1 + m); 26 int ret = inf; 27 rep(i, 1, m) { 28 rep(o, 1, n) sze[o] = 1, father[o] = o; 29 int ans = n * val[1]; 30 rep(j, i, m) { 31 if (j != i && edge[j].xx != edge[j - 1].xx) { 32 if (ans >= k) { 33 ret = min(ret, edge[j - 1].xx - edge[i].xx); 34 break; 35 } 36 } 37 int fx = getfather(edge[j].yy.xx), fy = getfather(edge[j].yy.yy); 38 if (fx != fy) { 39 father[fy] = fx; 40 ans -= val[sze[fy]] + val[sze[fx]]; 41 sze[fx] += sze[fy]; 42 sze[fy] = 0; 43 ans += val[sze[fx]]; 44 } 45 } 46 if (ans >= k) ret = min(ret, edge[m].xx - edge[i].xx); 47 } 48 if (ret == inf) puts("T_T"); 49 else printf("%d\n", ret); 50 return 0; 51 }
标签:
原文地址:http://www.cnblogs.com/y7070/p/5044859.html