結果

問題 No.1320 Two Type Min Cost Cycle
ユーザー tko919tko919
提出日時 2020-12-17 00:19:05
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 180 ms / 2,000 ms
コード長 1,407 bytes
コンパイル時間 1,916 ms
コンパイル使用メモリ 183,468 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-20 10:01:52
合計ジャッジ時間 5,382 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 2 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,368 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 4 ms
4,368 KB
testcase_08 AC 4 ms
4,368 KB
testcase_09 AC 150 ms
4,368 KB
testcase_10 AC 5 ms
4,368 KB
testcase_11 AC 99 ms
4,368 KB
testcase_12 AC 13 ms
4,368 KB
testcase_13 AC 47 ms
4,368 KB
testcase_14 AC 3 ms
4,368 KB
testcase_15 AC 5 ms
4,368 KB
testcase_16 AC 25 ms
4,368 KB
testcase_17 AC 3 ms
4,368 KB
testcase_18 AC 3 ms
4,368 KB
testcase_19 AC 58 ms
4,368 KB
testcase_20 AC 2 ms
4,368 KB
testcase_21 AC 133 ms
4,368 KB
testcase_22 AC 2 ms
4,368 KB
testcase_23 AC 2 ms
4,368 KB
testcase_24 AC 2 ms
4,368 KB
testcase_25 AC 2 ms
4,368 KB
testcase_26 AC 2 ms
4,368 KB
testcase_27 AC 2 ms
4,368 KB
testcase_28 AC 3 ms
4,368 KB
testcase_29 AC 85 ms
4,368 KB
testcase_30 AC 2 ms
4,368 KB
testcase_31 AC 16 ms
4,368 KB
testcase_32 AC 2 ms
4,368 KB
testcase_33 AC 104 ms
4,368 KB
testcase_34 AC 46 ms
4,368 KB
testcase_35 AC 7 ms
4,368 KB
testcase_36 AC 6 ms
4,368 KB
testcase_37 AC 3 ms
4,368 KB
testcase_38 AC 12 ms
4,368 KB
testcase_39 AC 4 ms
4,368 KB
testcase_40 AC 2 ms
4,368 KB
testcase_41 AC 2 ms
4,368 KB
testcase_42 AC 2 ms
4,368 KB
testcase_43 AC 8 ms
4,368 KB
testcase_44 AC 5 ms
4,368 KB
testcase_45 AC 180 ms
4,368 KB
testcase_46 AC 12 ms
4,368 KB
testcase_47 AC 42 ms
4,368 KB
testcase_48 AC 59 ms
4,368 KB
testcase_49 AC 9 ms
4,368 KB
testcase_50 AC 2 ms
4,368 KB
testcase_51 AC 2 ms
4,368 KB
testcase_52 AC 13 ms
4,368 KB
testcase_53 AC 8 ms
4,368 KB
testcase_54 AC 137 ms
4,368 KB
testcase_55 AC 137 ms
4,368 KB
testcase_56 AC 136 ms
4,368 KB
testcase_57 AC 132 ms
4,368 KB
testcase_58 AC 133 ms
4,368 KB
testcase_59 AC 132 ms
4,368 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
      |            ^

ソースコード

diff #

#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;}
//end

typedef 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;
}
0