結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 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 339 ms
199,424 KB
testcase_08 AC 311 ms
199,424 KB
testcase_09 AC 316 ms
199,424 KB
testcase_10 AC 3 ms
6,676 KB
testcase_11 AC 66 ms
31,488 KB
testcase_12 AC 358 ms
170,112 KB
testcase_13 AC 58 ms
25,344 KB
testcase_14 AC 269 ms
181,760 KB
testcase_15 AC 499 ms
176,256 KB
testcase_16 AC 20 ms
7,680 KB
testcase_17 AC 6 ms
6,676 KB
testcase_18 AC 46 ms
20,608 KB
testcase_19 AC 13 ms
8,192 KB
testcase_20 AC 95 ms
33,792 KB
testcase_21 AC 27 ms
7,424 KB
testcase_22 AC 346 ms
150,016 KB
testcase_23 AC 10 ms
6,676 KB
testcase_24 AC 47 ms
17,408 KB
testcase_25 AC 7 ms
6,676 KB
testcase_26 AC 68 ms
29,312 KB
testcase_27 AC 229 ms
181,888 KB
testcase_28 AC 207 ms
155,264 KB
testcase_29 AC 32 ms
15,488 KB
testcase_30 AC 350 ms
186,368 KB
testcase_31 AC 285 ms
199,552 KB
testcase_32 AC 259 ms
193,536 KB
testcase_33 WA -
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][y] > dp[r][i]+w) {
          if(r == n*2-1 && vis[y]) {
            cout << "inf" << endl;
            return 0;
          }
          dp[r+1][y] = dp[r][i]+w;
        }
      }
    }
  }
  cout << dp[n*2][n*2-1]*-1 << endl;
}
0