結果

問題 No.1480 Many Complete Graphs
ユーザー 蜜蜂蜜蜂
提出日時 2021-03-04 20:09:45
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 338 ms / 2,000 ms
コード長 1,095 bytes
コンパイル時間 1,677 ms
コンパイル使用メモリ 174,864 KB
実行使用メモリ 16,088 KB
最終ジャッジ日時 2023-09-16 02:42:58
合計ジャッジ時間 9,282 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 19 ms
7,264 KB
testcase_14 AC 15 ms
5,936 KB
testcase_15 AC 41 ms
8,168 KB
testcase_16 AC 21 ms
7,036 KB
testcase_17 AC 26 ms
6,672 KB
testcase_18 AC 6 ms
5,684 KB
testcase_19 AC 23 ms
6,240 KB
testcase_20 AC 42 ms
6,940 KB
testcase_21 AC 22 ms
6,964 KB
testcase_22 AC 13 ms
5,244 KB
testcase_23 AC 48 ms
10,984 KB
testcase_24 AC 83 ms
9,088 KB
testcase_25 AC 94 ms
10,372 KB
testcase_26 AC 118 ms
11,224 KB
testcase_27 AC 76 ms
8,820 KB
testcase_28 AC 156 ms
12,840 KB
testcase_29 AC 173 ms
13,888 KB
testcase_30 AC 155 ms
12,652 KB
testcase_31 AC 185 ms
13,712 KB
testcase_32 AC 228 ms
13,636 KB
testcase_33 AC 153 ms
12,540 KB
testcase_34 AC 155 ms
13,620 KB
testcase_35 AC 106 ms
12,652 KB
testcase_36 AC 119 ms
12,768 KB
testcase_37 AC 95 ms
12,596 KB
testcase_38 AC 110 ms
12,684 KB
testcase_39 AC 105 ms
12,724 KB
testcase_40 AC 107 ms
12,464 KB
testcase_41 AC 139 ms
12,660 KB
testcase_42 AC 83 ms
12,568 KB
testcase_43 AC 108 ms
12,548 KB
testcase_44 AC 112 ms
12,824 KB
testcase_45 AC 118 ms
12,588 KB
testcase_46 AC 126 ms
12,604 KB
testcase_47 AC 284 ms
16,088 KB
testcase_48 AC 338 ms
15,916 KB
testcase_49 AC 327 ms
15,940 KB
testcase_50 AC 74 ms
14,912 KB
testcase_51 AC 293 ms
16,004 KB
testcase_52 AC 108 ms
13,712 KB
testcase_53 AC 81 ms
14,064 KB
testcase_54 AC 92 ms
13,860 KB
testcase_55 AC 90 ms
14,072 KB
testcase_56 AC 109 ms
13,884 KB
testcase_57 AC 81 ms
14,872 KB
testcase_58 AC 75 ms
14,128 KB
evil_aftercontest.txt AC 149 ms
25,384 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: 関数 ‘int main()’ 内:
main.cpp:44:10: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   44 |     auto [now,dist] = que.top();
      |          ^
main.cpp:51:14: 警告: structured bindings only available with ‘-std=c++17’ or ‘-std=gnu++17’ [-Wc++17-extensions]
   51 |     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,1});
    graph[n+2*i+1].pb({n+2*i,1});
    for(int j=0;j<k;j++){
      int s;
      cin>>s;
      if(s%2==1){
        graph[s-1].pb({n+2*i,s+c});
        graph[n+2*i].pb({s-1,s+c});
      }
      else{
        graph[s-1].pb({n+2*i+1,s+c});
        graph[n+2*i+1].pb({s-1,s+c});
      }
    }
  }

  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]=-2;
  }
  cout<<ans[n-1]/2<<endl;
}
0