[CF707B]Bakery(暴力)
题目链接:http://codeforces.com/contest/707/problem/B
题意:一张图,点被分为两个集合,求两个集合中各取一个点之间距离最小。
遍历一个点集,去找这个集合中的某点的邻边,一定有一个点是另一个点集的。
1 /* 2 ━━━━━┒ギリギリ♂ eye! 3 ┓┏┓┏┓┃キリキリ♂ mind! 4 ┛┗┛┗┛┃\○/ 5 ┓┏┓┏┓┃ / 6 ┛┗┛┗┛┃ノ) 7 ┓┏┓┏┓┃ 8 ┛┗┛┗┛┃ 9 ┓┏┓┏┓┃ 10 ┛┗┛┗┛┃ 11 ┓┏┓┏┓┃ 12 ┛┗┛┗┛┃ 13 ┓┏┓┏┓┃ 14 ┃┃┃┃┃┃ 15 ┻┻┻┻┻┻ 16 */ 17 #include <algorithm> 18 #include <iostream> 19 #include <iomanip> 20 #include <cstring> 21 #include <climits> 22 #include <complex> 23 #include <cassert> 24 #include <cstdio> 25 #include <bitset> 26 #include <vector> 27 #include <deque> 28 #include <queue> 29 #include <stack> 30 #include <ctime> 31 #include <set> 32 #include <map> 33 #include <cmath> 34 //#include <unordered_map> 35 using namespace std; 36 #define fr first 37 #define sc second 38 #define cl clear 39 #define BUG puts("here!!!") 40 #define W(a) while(a--) 41 #define pb(a) push_back(a) 42 #define Rint(a) scanf("%d", &a) 43 #define Rll(a) scanf("%I64d", &a) 44 #define Rs(a) scanf("%s", a) 45 #define Cin(a) cin >> a 46 #define FRead() freopen("in", "r", stdin) 47 #define FWrite() freopen("out", "w", stdout) 48 #define Rep(i, len) for(int i = 0; i < (len); i++) 49 #define For(i, a, len) for(int i = (a); i < (len); i++) 50 #define Cls(a) memset((a), 0, sizeof(a)) 51 #define Clr(a, x) memset((a), (x), sizeof(a)) 52 #define Full(a) memset((a), 0x7f7f7f, sizeof(a)) 53 #define lrt rt << 1 54 #define rrt rt << 1 | 1 55 #define pi 3.14159265359 56 #define RT return 57 #define lowbit(x) x & (-x) 58 #define onenum(x) __builtin_popcount(x) 59 typedef long long LL; 60 typedef long double LD; 61 typedef unsigned long long ULL; 62 typedef pair<int, int> pii; 63 typedef pair<string, int> psi; 64 typedef pair<LL, LL> pll; 65 typedef map<string, int> msi; 66 typedef vector<int> vi; 67 typedef vector<LL> vl; 68 typedef vector<vl> vvl; 69 typedef vector<bool> vb; 70 71 typedef pair<LL, LL> PII; 72 const int maxn = 100100; 73 int n, m, k; 74 75 typedef struct E { 76 LL w; 77 int v; 78 E() {} 79 E(int vv, int ww) : v(vv), w(ww) {} 80 }E; 81 82 int vis[maxn]; 83 vector<E> e[maxn]; 84 int x[maxn]; 85 int u, v, w; 86 LL ret; 87 88 int main() { 89 // FRead(); 90 while(~Rint(n) && ~Rint(m) && ~Rint(k)) { 91 ret = 0x7f7f7f7f; Cls(vis); 92 Rep(i, n+10) e[i].clear(); 93 Rep(i, m) { 94 Rint(u); Rint(v); Rint(w); 95 e[u].push_back(E(v, w)); 96 e[v].push_back(E(u, w)); 97 } 98 Rep(i, k) { 99 Rint(x[i]); 100 vis[x[i]] = 1; 101 } 102 103 For(i, 1, n+1) { 104 Rep(j, e[i].size()) { 105 if(vis[e[i][j].v] == 0 && vis[i] == 1) { 106 ret = min(ret, e[i][j].w); 107 } 108 } 109 } 110 if(ret == 0x7f7f7f7f) puts("-1"); 111 else cout << ret << endl; 112 } 113 RT 0; 114 }