結果
問題 | No.114 遠い未来 |
ユーザー | HIR180 |
提出日時 | 2020-04-22 14:25:58 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 774 ms / 5,000 ms |
コード長 | 3,365 bytes |
コンパイル時間 | 3,452 ms |
コンパイル使用メモリ | 254,700 KB |
実行使用メモリ | 12,796 KB |
最終ジャッジ日時 | 2024-10-11 07:09:14 |
合計ジャッジ時間 | 8,745 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
12,672 KB |
testcase_01 | AC | 260 ms
12,672 KB |
testcase_02 | AC | 772 ms
12,672 KB |
testcase_03 | AC | 23 ms
5,248 KB |
testcase_04 | AC | 8 ms
12,672 KB |
testcase_05 | AC | 9 ms
12,672 KB |
testcase_06 | AC | 774 ms
12,672 KB |
testcase_07 | AC | 8 ms
12,672 KB |
testcase_08 | AC | 9 ms
12,672 KB |
testcase_09 | AC | 11 ms
12,672 KB |
testcase_10 | AC | 41 ms
12,672 KB |
testcase_11 | AC | 92 ms
12,672 KB |
testcase_12 | AC | 255 ms
12,796 KB |
testcase_13 | AC | 251 ms
12,704 KB |
testcase_14 | AC | 768 ms
12,664 KB |
testcase_15 | AC | 757 ms
12,672 KB |
testcase_16 | AC | 130 ms
5,248 KB |
testcase_17 | AC | 71 ms
5,248 KB |
testcase_18 | AC | 105 ms
5,248 KB |
testcase_19 | AC | 48 ms
5,248 KB |
testcase_20 | AC | 15 ms
5,248 KB |
testcase_21 | AC | 4 ms
5,248 KB |
testcase_22 | AC | 6 ms
5,248 KB |
testcase_23 | AC | 2 ms
5,248 KB |
testcase_24 | AC | 2 ms
5,248 KB |
testcase_25 | AC | 2 ms
5,248 KB |
testcase_26 | AC | 2 ms
5,248 KB |
testcase_27 | AC | 2 ms
5,248 KB |
ソースコード
//Let's join Kaede Takagaki Fan Club !! //#pragma GCC optimize("Ofast") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) #define all(x) x.begin(),x.end() template<class T> void dmp(T a){ rep(i,a.size()) cout << a[i] << " "; cout << endl; } template<class T> bool chmax(T&a, T b){ if(a < b){ a = b; return 1; } return 0; } template<class T> bool chmin(T&a, T b){ if(a > b){ a = b; return 1; } return 0; } template<class T> void g(T &a){ cin >> a; } template<class T> void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 1000000007;//998244353 template<class T> void add(T&a,T b){ a+=b; if(a >= mod) a-=mod; } int n, m, t; int w[36][36]; vector<P1>edge; vector<int>imp; int dp[(1<<16)][36]; void solve_steiner(){ repn(i, (1<<16)-1) rep(j, 36) dp[i][j] = INF; rep(i, imp.size()){ rep(j, n){ dp[(1<<i)][j] = w[imp[i]][j]; } } for(int x=0;x<(1<<t);x++){ if(__builtin_popcount(x) <= 1) continue; int sub = x; while(1){ rep(y, n) chmin(dp[x][y], dp[sub][y] + dp[sub^x][y]); if(sub == 0) break; sub = (sub-1) & x; } rep(y, n) rep(z, n){ chmin(dp[x][y], dp[x][z] + w[y][z]); } } int ans = INF; rep(x, n) chmin(ans, dp[(1<<t)-1][x]); cout << ans << endl; } struct uf{ int par[36]; void init(){ rep(i, 36) par[i] = i; } int find(int x){ if(x == par[x]) return x; else return par[x] = find(par[x]); } void unite(int x, int y){ x = find(x); y = find(y); if(x == y) return; par[x] = y; } bool same(int x, int y){ return find(x) == find(y); } }kaede; void solve_MST(){ vector<int>ump; bool ex[36]={}; rep(i, imp.size()) ex[imp[i]] = 1; rep(i, n) if(!ex[i]) ump.pb(i); int sz = ump.size(), ans = INF; rep(mask, (1<<sz)){ int N = t + __builtin_popcount(mask); int cnt = 0, use = 0; bool eex[36] = {}; rep(i, sz) if(((mask>>i)&1)) eex[ump[i]] = 1; kaede.init(); rep(i, edge.size()){ int a = edge[i].sc.fi, b = edge[i].sc.sc; if(!ex[a] && !eex[a]) continue; if(!ex[b] && !eex[b]) continue; if(kaede.same(a, b)) continue; kaede.unite(a, b); cnt ++; use += edge[i].fi; if(ans <= use) break; } if(cnt == N-1) chmin(ans, use); } cout << ans << endl; } int main(){ cin >> n >> m >> t; rep(i, 36) rep(j, 36){ if(i != j) w[i][j] = 1e7; } rep(i, m){ int a, b, c; cin >> a >> b >> c; a --; b --; w[a][b] = w[b][a] = c; edge.pb(mp(c, mp(a, b))); } sort(all(edge)); imp.resize(t); rep(i, t){ cin >> imp[i]; imp[i] --; } rep(x, n) rep(i, n) rep(j, n) chmin(w[i][j], w[i][x] + w[x][j]); if(t <= 16) solve_steiner(); else solve_MST(); }