結果
| 問題 |
No.1308 ジャンプビーコン
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2020-12-05 14:31:02 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 928 ms / 4,000 ms |
| コード長 | 1,602 bytes |
| コンパイル時間 | 2,664 ms |
| コンパイル使用メモリ | 208,972 KB |
| 最終ジャッジ日時 | 2025-01-16 17:49:24 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 37 |
コンパイルメッセージ
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:34:10: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
| ^~~~
main.cpp:34:18: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
| ^~~~
main.cpp:34:27: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
| ^~~~
main.cpp:34:37: warning: use of ‘auto’ in parameter declaration only available with ‘-std=c++20’ or ‘-fconcepts’
34 | void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
| ^~~~
main.cpp: In function ‘int main()’:
main.cpp:56:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
56 | scanf("%d %d %d",&u,&v,&l);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
main.cpp:65:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
65 | scanf("%d",&x[i]);
| ~~~~~^~~~~~~~~~~~
ソースコード
#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 100000000000000000
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;
}
long long C;
void dfs(auto &E,auto &dp,auto &ndp,auto &dis,int now,int F,int P,int p=-1){
if(F!=now)ndp[now] = min(ndp[now],dp[now] + C + dis[now][P]);
else ndp[now] = min(ndp[now],dp[now] + dis[now][P]);
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>>());
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);
}
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;
}
沙耶花