提出 #33603896


ソースコード 拡げる

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

typedef long long ll;
#define rep(i,a,n) for (ll i=a;i<(ll)n;i++)

ll read(){ll r;scanf("%lld",&r);return r;} // read

ll dp[2][200010];
ll mx[200010]; // 只记录1的, 因为0的直接记录在pq和dp中, 而1的在子节点未完全计算时pq和dp都不会记录
int deg[200010]; // 正向图出度, 反向图入度
vector<pair<int,int> > g[200010]; // 反向图 v = {u, weight}

template <typename T>
using minPQ = priority_queue<T,vector<T>, greater<T>>; // 小根堆

int main(){
  int n = read();
  int m = read();
  int v = read();// 起点
  rep(i,0,2) fill(dp[i],dp[i]+n+1,-1); // 未访问
  rep(i,0,m) {
    int u = read();
    int v = read();
    int w = read();
    g[v].push_back({u, w});
    deg[u] ++;
  }
  minPQ<array<ll,3>> q; // 小根堆, dij 每次找最小的未达点变为可达 {距离, 0/1, 点}
  rep(i,1,n+1) if(deg[i] == 0) rep(j,0,2) q.push({0, j, i}); // dp[0/1][i] 反向入度为0 的节点
  while(q.size()) {
    auto [d, i, u] = q.top(); q.pop();
    if(dp[i][u] != -1) continue; // 计算过
    dp[i][u] = d; // 更新值
    if(!i) { // dp[0][u] -> dp[1][v]
      for(auto [v, w] : g[u]) { // 更新反向边 并更新 deg[v] --
        mx[v] = max(mx[v], d + w); // 更新值但是 不一定进入pq dp[x][1] = max (f[y][0] + weight[x][y])
        if(--deg[v] == 0) q.push({mx[v], 1, v}); // dp[1][v] 只能所有计算都计算后才有意义
      }
    } else for(auto [v, w] : g[u]) q.push({d + w, 0, v}); // dp[1][u] -> dp[0][v] dij
  }
  if(dp[0][v] == -1) printf("INFINITY\n");
  else printf("%lld\n", dp[0][v]);
  return 0;
}

提出情報

提出日時
問題 Ex - Game on Graph
ユーザ cromarmot
言語 C++ (GCC 9.2.1)
得点 600
コード長 1667 Byte
結果 AC
実行時間 223 ms
メモリ 30608 KiB

コンパイルエラー

./Main.cpp: In function ‘ll read()’:
./Main.cpp:7:21: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
    7 | ll read(){ll r;scanf("%lld",&r);return r;} // read
      |                ~~~~~^~~~~~~~~~~

ジャッジ結果

セット名 Sample All After Contest
得点 / 配点 0 / 0 600 / 600 0 / 0
結果
AC × 3
AC × 67
AC × 3
セット名 テストケース
Sample sample_01.txt, sample_02.txt, sample_03.txt
All random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_51.txt, random_52.txt, random_53.txt, random_54.txt, random_55.txt, random_56.txt, random_57.txt, random_58.txt, random_59.txt, random_60.txt, random_61.txt, random_62.txt, random_63.txt, random_64.txt, random_65.txt, random_66.txt, random_67.txt, random_68.txt, random_69.txt, random_70.txt, random_71.txt, random_72.txt, random_73.txt, random_74.txt, random_75.txt, random_76.txt, random_77.txt, random_78.txt, random_79.txt, random_80.txt, hand_01.txt, hand_02.txt, sample_01.txt, sample_02.txt, sample_03.txt
After Contest after_contest_01.txt, after_contest_02.txt, after_contest_03.txt
ケース名 結果 実行時間 メモリ
after_contest_01.txt AC 10 ms 8440 KiB
after_contest_02.txt AC 94 ms 18840 KiB
after_contest_03.txt AC 84 ms 14972 KiB
hand_01.txt AC 10 ms 8284 KiB
hand_02.txt AC 11 ms 8444 KiB
random_01.txt AC 150 ms 21588 KiB
random_02.txt AC 23 ms 8756 KiB
random_03.txt AC 137 ms 21800 KiB
random_04.txt AC 22 ms 9228 KiB
random_05.txt AC 176 ms 22136 KiB
random_06.txt AC 40 ms 9776 KiB
random_07.txt AC 144 ms 21696 KiB
random_08.txt AC 26 ms 9344 KiB
random_09.txt AC 84 ms 24488 KiB
random_10.txt AC 11 ms 8416 KiB
random_11.txt AC 154 ms 21628 KiB
random_12.txt AC 17 ms 8884 KiB
random_13.txt AC 161 ms 21508 KiB
random_14.txt AC 25 ms 8900 KiB
random_15.txt AC 119 ms 25860 KiB
random_16.txt AC 11 ms 8344 KiB
random_17.txt AC 201 ms 23708 KiB
random_18.txt AC 64 ms 11112 KiB
random_19.txt AC 197 ms 23736 KiB
random_20.txt AC 34 ms 10304 KiB
random_21.txt AC 208 ms 24344 KiB
random_22.txt AC 86 ms 15336 KiB
random_23.txt AC 67 ms 11272 KiB
random_24.txt AC 82 ms 12952 KiB
random_25.txt AC 156 ms 24328 KiB
random_26.txt AC 167 ms 24312 KiB
random_27.txt AC 134 ms 20060 KiB
random_28.txt AC 149 ms 20056 KiB
random_29.txt AC 100 ms 16256 KiB
random_30.txt AC 103 ms 16096 KiB
random_31.txt AC 9 ms 8344 KiB
random_32.txt AC 8 ms 8336 KiB
random_51.txt AC 27 ms 9392 KiB
random_52.txt AC 30 ms 9424 KiB
random_53.txt AC 46 ms 10000 KiB
random_54.txt AC 47 ms 10336 KiB
random_55.txt AC 62 ms 10024 KiB
random_56.txt AC 59 ms 10140 KiB
random_57.txt AC 122 ms 17080 KiB
random_58.txt AC 113 ms 17180 KiB
random_59.txt AC 197 ms 30608 KiB
random_60.txt AC 199 ms 30352 KiB
random_61.txt AC 157 ms 21624 KiB
random_62.txt AC 160 ms 21768 KiB
random_63.txt AC 198 ms 30588 KiB
random_64.txt AC 197 ms 30440 KiB
random_65.txt AC 154 ms 21656 KiB
random_66.txt AC 159 ms 21640 KiB
random_67.txt AC 100 ms 19272 KiB
random_68.txt AC 92 ms 19336 KiB
random_69.txt AC 190 ms 24352 KiB
random_70.txt AC 193 ms 24404 KiB
random_71.txt AC 223 ms 24304 KiB
random_72.txt AC 214 ms 24308 KiB
random_73.txt AC 217 ms 22020 KiB
random_74.txt AC 208 ms 22016 KiB
random_75.txt AC 182 ms 22656 KiB
random_76.txt AC 179 ms 22736 KiB
random_77.txt AC 176 ms 23392 KiB
random_78.txt AC 188 ms 23432 KiB
random_79.txt AC 188 ms 23504 KiB
random_80.txt AC 181 ms 23240 KiB
sample_01.txt AC 8 ms 8352 KiB
sample_02.txt AC 8 ms 8280 KiB
sample_03.txt AC 10 ms 8352 KiB