結果
問題 | No.1308 ジャンプビーコン |
ユーザー | 沙耶花 |
提出日時 | 2020-12-05 14:25:00 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,254 bytes |
コンパイル時間 | 2,651 ms |
コンパイル使用メモリ | 222,448 KB |
実行使用メモリ | 74,880 KB |
最終ジャッジ日時 | 2024-09-15 17:23:00 |
合計ジャッジ時間 | 19,770 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 2 ms
5,376 KB |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | AC | 2 ms
5,376 KB |
testcase_06 | AC | 2 ms
5,376 KB |
testcase_07 | AC | 2 ms
5,376 KB |
testcase_08 | AC | 2 ms
5,376 KB |
testcase_09 | AC | 2 ms
5,376 KB |
testcase_10 | AC | 2 ms
5,376 KB |
testcase_11 | AC | 2 ms
5,376 KB |
testcase_12 | AC | 3 ms
5,376 KB |
testcase_13 | AC | 11 ms
5,376 KB |
testcase_14 | AC | 11 ms
5,376 KB |
testcase_15 | AC | 10 ms
5,376 KB |
testcase_16 | AC | 11 ms
5,376 KB |
testcase_17 | AC | 11 ms
5,376 KB |
testcase_18 | AC | 825 ms
74,368 KB |
testcase_19 | AC | 840 ms
74,496 KB |
testcase_20 | AC | 827 ms
74,368 KB |
testcase_21 | AC | 820 ms
74,496 KB |
testcase_22 | AC | 844 ms
74,496 KB |
testcase_23 | AC | 2 ms
5,376 KB |
testcase_24 | AC | 2 ms
5,376 KB |
testcase_25 | AC | 2 ms
5,376 KB |
testcase_26 | AC | 701 ms
74,496 KB |
testcase_27 | AC | 712 ms
74,496 KB |
testcase_28 | AC | 700 ms
74,496 KB |
testcase_29 | AC | 758 ms
74,752 KB |
testcase_30 | AC | 748 ms
74,752 KB |
testcase_31 | WA | - |
testcase_32 | AC | 841 ms
74,880 KB |
testcase_33 | AC | 905 ms
74,880 KB |
testcase_34 | AC | 691 ms
74,496 KB |
testcase_35 | AC | 693 ms
74,368 KB |
testcase_36 | AC | 734 ms
74,368 KB |
testcase_37 | AC | 733 ms
74,496 KB |
testcase_38 | AC | 874 ms
74,496 KB |
testcase_39 | AC | 885 ms
74,496 KB |
コンパイルメッセージ
main.cpp:13:33: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 13 | vector<long long> get(int start,auto &E){ | ^~~~ main.cpp:118:10: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 118 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){ | ^~~~ main.cpp:118:18: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 118 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){ | ^~~~ main.cpp:118:27: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 118 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){ | ^~~~ main.cpp:118:37: warning: use of 'auto' in parameter declaration only available with '-std=c++20' or '-fconcepts' 118 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){ | ^~~~
ソースコード
#pragma target("avx2") #pragma optimize("O3") #pragma optimize("unroll-loops") #include <stdio.h> #include <bits/stdc++.h> using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000000000 vector<long long> get(int start,auto &E){ vector<long long> dis(E.size(),Inf); dis[start] = 0; queue<int> Q; Q.push(start); while(Q.size()>0){ int u = Q.front(); Q.pop(); rep(i,E[u].size()){ int v = E[u][i].first; if(dis[v]!=Inf)continue; dis[v] = dis[u] + E[u][i].second; Q.push(v); } } return dis; } struct HLD{ vector<int> sz,parent,depth,root,pos; vector<int> arr; HLD(vector<vector<int>> &E){ sz.resize(E.size(),1); parent.resize(E.size(),0); depth.resize(E.size(),0); root.resize(E.size(),0); pos.resize(E.size(),0); dfs(0,-1,E); dfs2(0,-1,E,0); } void dfs(int now,int p,vector<vector<int>> &E){ parent[now] = p; if(p==-1){ depth[now] = 0; } else{ depth[now] = depth[p]+1; } for(int i=0;i<E[now].size();i++){ int to = E[now][i]; if(to==p)continue; dfs(to,now,E); sz[now] += sz[to]; } } void dfs2(int now,int p,vector<vector<int>> &E,int r){ pos[now] = arr.size(); arr.push_back(now); root[now] = r; int maxi = 0; int ind = -1; for(int i=0;i<E[now].size();i++){ int to = E[now][i]; if(to==p)continue; if(maxi<sz[to]){ maxi = sz[to]; ind = to; } } if(ind==-1)return; dfs2(ind,now,E,r); for(int i=0;i<E[now].size();i++){ int to = E[now][i]; if(to==p||to==ind)continue; dfs2(to,now,E,to); } } vector<pair<int,int>> query(int u,int v){ vector<pair<int,int>> ret; int t = 0; while(root[u]!=root[v]){ if(depth[root[u]] <= depth[root[v]]){ ret.insert(ret.begin()+t,{pos[root[v]], pos[v]}); v = parent[root[v]]; } else{ ret.insert(ret.begin()+t,{pos[u],pos[root[u]]}); u = parent[root[u]]; t++; } } ret.insert(ret.begin()+t,{pos[u],pos[v]}); return ret; } int lca(int u,int v){ for(;;v=parent[root[v]]){ if(pos[u]>pos[v])swap(u,v); if(root[u]==root[v])return u; } } int get_distance(int u,int v){ return depth[u] + depth[v] - 2 * depth[lca(u,v)]; } }; long long C; void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){ ndp[now] = dp[now] + C + dis[now][P]; if(F==now)ndp[now] -= C; rep(i,E[now].size()){ int to = E[now][i].first; if(to==p)continue; dfs(E,dp,ndp,dis,to,F,P,now); ndp[now] = min(ndp[now],ndp[to]); } } int main(){ int N,Q; cin>>N>>Q>>C; vector E(N,vector<pair<int,long long>>()); vector EE(N,vector<int>()); rep(i,N-1){ int u,v,l; scanf("%d %d %d",&u,&v,&l); u--;v--; E[u].emplace_back(v,l); E[v].emplace_back(u,l); EE[u].push_back(v); EE[v].push_back(u); } vector<int> x(Q); rep(i,Q){ scanf("%d",&x[i]); x[i]--; } vector dis(N,vector<long long>()); rep(i,N){ dis[i] = get(i,E); } vector<long long> dp(N,Inf); dp[x[0]] = 0LL; rep(i,Q-1){ vector<long long> ndp(N,Inf); dfs(E,dp,ndp,dis,x[i+1],x[i],x[i+1]); rep(j,N){ ndp[j] = min(ndp[j],dp[j] + dis[x[i]][x[i+1]]); } swap(dp,ndp); } long long ans = Inf; rep(i,N)ans = min(ans,dp[i]); cout<<ans<<endl; return 0; }