# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
338137 | 2020-12-22T14:55:31 Z | KazamaHoang | Cities (BOI16_cities) | C++14 | 263 ms | 14828 KB |
/* -> Written by <- ----------- K_A_Z_A_M_A ___________ _ | | (^_^) | | /( | )\ | |____|_|____| H O A N G */ #include <bits/stdc++.h> #define Task "" #define F first #define S second #define pb push_back #define bit(x, i) ((x >> (i)) & 1) #define inf 1e9 + 7 #define INF 1e18 + 7 #define ll long long #define pii pair <int, int> #define debug(x) cerr << #x << " is " << x << "\n"; using namespace std; const int MOD = 1e9 + 7; const int maxn = 1e5 + 5; int n, k, m; vector <pair<int, int>> ke[maxn]; pair <int, pair<int, int>> e[maxn]; bool dd[maxn]; int b[maxn]; int root[21]; int Get_Root(int u){ if (root[u] != u) root[u] = Get_Root(root[u]); return root[u]; } ll Cal(int mask){ for (int i = 1; i <= n; ++ i) root[i] = i; int cnt = 0; ll res = 0; for (int i = 1; i <= m; ++ i){ int u = e[i].S.F; int v = e[i].S.S; int w = e[i].F; if (bit(mask, u-1) && bit(mask, v-1)){ u = Get_Root(u); v = Get_Root(v); if (u == v) continue; root[u] = v; res += w; } } for (int i = 1; i < k; ++ i){ int u = Get_Root(b[i]); for (int j = i + 1; j <= k; ++ j){ int v = Get_Root(b[j]); if (u != v) return INF; } } return res; } void Solve(){ cin >> n >> k >> m; for (int i = 1; i <= k; ++ i){ cin >> b[i]; } for (int i = 1; i <= m; ++ i){ int u, v, w; cin >> u >> v >> w; ke[u].pb({v, w}); ke[v].pb({u, w}); e[i] = {w, {u, v}}; } sort(e + 1, e + 1 + m); ll ans = INF; for (int mask = 0; mask < (1 << n); ++ mask) ans = min(ans, Cal(mask)); cout << ans; } int main(){ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); if(fopen(Task".inp", "r")){ freopen(Task".inp","r",stdin); freopen(Task".out","w",stdout); } int test_case = 1; // cin >> test_case; while (test_case --){ Solve(); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 2668 KB | Output is correct |
2 | Correct | 253 ms | 2668 KB | Output is correct |
3 | Correct | 263 ms | 2668 KB | Output is correct |
4 | Correct | 238 ms | 2668 KB | Output is correct |
5 | Correct | 263 ms | 2668 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 70 ms | 14828 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 2796 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 72 ms | 14828 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 81 ms | 14828 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |