結果
問題 | No.1320 Two Type Min Cost Cycle |
ユーザー |
![]() |
提出日時 | 2020-12-17 00:19:05 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 167 ms / 2,000 ms |
コード長 | 1,407 bytes |
コンパイル時間 | 1,762 ms |
コンパイル使用メモリ | 182,280 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-09-20 05:30:41 |
合計ジャッジ時間 | 5,606 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 57 |
コンパイルメッセージ
main.cpp: In function 'll dijk(int, int)': main.cpp:25:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 25 | auto [d,x]=pq.top(); pq.pop(); | ^ main.cpp:28:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 28 | for(auto [to,add]:g[x]){ | ^ main.cpp: In function 'int main()': main.cpp:48:13: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 48 | for(auto [p,w]:es){ | ^ main.cpp:49:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions] 49 | auto [u,v]=p; | ^
ソースコード
#define _USE_MATH_DEFINES#include <bits/stdc++.h>using namespace std;//template#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)#define ALL(v) (v).begin(),(v).end()typedef long long int ll;const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}//endtypedef pair<ll,ll> P;typedef pair<P,ll> T;int t,n,m;set<P> g[2010];ll dijk(int u,int v){ll dist[2010];rep(i,0,n)dist[i]=INF;dist[u]=0;priority_queue<P,vector<P>,greater<P>> pq;pq.push({0,u});while(!pq.empty()){auto [d,x]=pq.top(); pq.pop();if(dist[x]<d)continue;if(x==v)return d;for(auto [to,add]:g[x]){if(chmin(dist[to],d+add)){pq.push({dist[to],to});}}}return INF;}int main(){cin>>t>>n>>m;vector<T> es;rep(i,0,m){int u,v,w; cin>>u>>v>>w;u--; v--;es.push_back({{u,v},w});g[u].insert({v,w});if(!t)g[v].insert({u,w});}ll res=INF;for(auto [p,w]:es){auto [u,v]=p;g[u].erase({v,w});if(!t)g[v].erase({u,w});chmin(res,dijk(v,u)+w);g[u].insert({v,w});if(!t)g[v].insert({u,w});}if(res==INF)puts("-1");else cout<<res<<endl;return 0;}