結果

問題 No.1480 Many Complete Graphs
ユーザー 蜜蜂
提出日時 2021-03-04 19:55:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 939 bytes
コンパイル時間 1,899 ms
コンパイル使用メモリ 176,336 KB
実行使用メモリ 15,616 KB
最終ジャッジ日時 2024-07-03 04:02:33
合計ジャッジ時間 9,268 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46 WA * 11
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int main()':
main.cpp:37:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   37 |     auto [now,dist] = que.top();
      |          ^
main.cpp:44:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   44 |     for(auto [next,dist2] : graph[now]){
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld = long double;
#define fi first
#define se second
#define pb push_back

using T = pair<int,ll>;

int main(){
  int n,m;
  cin>>n>>m;

  vector<vector<T>> graph(n+2*m);
  vector<ll> ans(n+2*m,1e18);
  ans[0]=0;
  
  for(int i=0;i<m;i++){
    int k;
    ll c;
    cin>>k>>c;
    graph[n+2*i].pb({n+2*i+1,c});
    for(int j=0;j<k;j++){
      int s;
      cin>>s;
      graph[s-1].pb({n+2*i,(s+1)/2});
      graph[n+2*i+1].pb({s-1,s/2});
    }
  }

  priority_queue<T,vector<T>,greater<T>> que;
  que.push({0,0});

  while(!que.empty()){
    auto [now,dist] = que.top();
    que.pop();

    if(dist>ans[now]){
      continue;
    }

    for(auto [next,dist2] : graph[now]){
      if(ans[now]+dist2<ans[next]){
        que.push({next,dist2});
        ans[next]=ans[now]+dist2;
      }
    }
  }
  
  if(ans[n-1]>=1e18){
    ans[n-1]=-1;
  }
  cout<<ans[n-1]<<endl;
}
0