結果

問題 No.2712 Play more!
ユーザー a1048576a1048576
提出日時 2024-04-06 19:24:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 383 ms / 2,000 ms
コード長 1,305 bytes
コンパイル時間 2,144 ms
コンパイル使用メモリ 185,692 KB
実行使用メモリ 199,552 KB
最終ジャッジ日時 2024-04-06 19:24:51
合計ジャッジ時間 7,476 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 322 ms
199,424 KB
testcase_08 AC 302 ms
199,424 KB
testcase_09 AC 302 ms
199,424 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 64 ms
31,488 KB
testcase_12 AC 321 ms
170,112 KB
testcase_13 AC 45 ms
25,344 KB
testcase_14 AC 277 ms
181,760 KB
testcase_15 AC 383 ms
176,256 KB
testcase_16 AC 16 ms
7,680 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 37 ms
20,608 KB
testcase_19 AC 11 ms
8,192 KB
testcase_20 AC 67 ms
33,792 KB
testcase_21 AC 19 ms
7,424 KB
testcase_22 AC 291 ms
150,016 KB
testcase_23 AC 8 ms
6,676 KB
testcase_24 AC 32 ms
17,408 KB
testcase_25 AC 6 ms
6,676 KB
testcase_26 AC 53 ms
29,312 KB
testcase_27 AC 253 ms
181,888 KB
testcase_28 AC 206 ms
155,264 KB
testcase_29 AC 32 ms
15,488 KB
testcase_30 AC 322 ms
186,368 KB
testcase_31 AC 260 ms
199,552 KB
testcase_32 AC 267 ms
193,536 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
  int n,m;
  cin >> n >> m;
  vector<vector<pair<int,int>>> a(n*2);
  vector<vector<int>> b(n*2);
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[i].push_back({n+i,-x});
    b[n+i].push_back(i);
  }
  while(m--) {
    int x,y,w;
    cin >> x >> y >> w;
    x--,y--;
    a[x+n].push_back({y,w});
    b[y].push_back(x+n);
  }
  vector<bool> vis(n*2,false);
  vis[n*2-1] = true;
  deque<int> Q;
  Q.push_back(n*2-1);
  while(Q.size() > 0) {
    int x = Q.front();
    Q.pop_front();
    int l = b[x].size();
    for(int i = 0; i < l; i++) {
      int y = b[x][i];
      if(!vis[y]) {
        vis[y] = true;
        Q.push_back(y);
      }
    }
  }
  vector<vector<int>> dp(n*2+1,vector<int>(n*2,1e18));
  dp[0][0] = 0;
  for(int r = 0; r < n*2; r++) {
  	for(int i = 0; i < n*2; i++) dp[r+1][i] = dp[r][i];
    for(int i = 0; i < n*2; i++) {
      int l = a[i].size();
      for(int j = 0; j < l; j++) {
        int y,w;
        tie(y,w) = a[i][j];
        if(dp[r+1][y] > dp[r][i]+w) {
          if(r == n*2-1 && vis[y]) {
            cout << "inf" << endl;
            return 0;
          }
          dp[r+1][y] = min(dp[r+1][y],dp[r][i]+w);
        }
      }
    }
  }
  cout << dp[n*2][n*2-1]*-1 << endl;
}
0