結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー 👑 Nachia
提出日時 2021-01-22 23:33:56
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,011 bytes
コンパイル時間 2,076 ms
コンパイル使用メモリ 201,412 KB
最終ジャッジ日時 2025-01-18 06:21:59
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 43 WA * 2
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:22:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   22 |   scanf("%d%d",&N,&n); N++;
      |   ~~~~~^~~~~~~~~~~~~~
main.cpp:25:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   25 |     int u,v,d,t; scanf("%d%d%d%d",&u,&v,&d,&t);
      |                  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

const ULL M=1000000007;

struct Edge{
  int to;
  ULL d,t;
};

int N,n;
vector<Edge> E[100001];
int I[100001];
vector<int> Ord;
ULL dpc[100001];
ULL dp[100001];

int main() {
  scanf("%d%d",&N,&n); N++;
  rep(i,N) I[i]=0;
  rep(i,n){
    int u,v,d,t; scanf("%d%d%d%d",&u,&v,&d,&t);
    E[u].push_back({v,(ULL)d,(ULL)t});
    I[v]++;
  }
  {
    queue<int> Q; rep(i,N) if(I[i]==0) Q.push(i);
    vector<int> Iin(N);
    while(Q.size()){
      int p=Q.front(); Q.pop();
      Ord.push_back(p);
      Iin[p]=1;
      for(auto& e:E[p]) if((--I[e.to])==0) Q.push(e.to);
    }
    if(Iin[0]==0 || Iin[N-1]==0){ printf("INF\n"); return 0; }
  }
  rep(i,N) dp[i]=dpc[i]=0;
  dpc[0]=1;
  for(int p:Ord){
    for(Edge e:E[p]){
      dpc[e.to] = (dpc[e.to]+dpc[p]*e.t)%M;
      dp[e.to] = (dp[e.to]+(dp[p]+e.d*dpc[p])%M*e.t)%M;
    }
  }
  printf("%llu\n",dp[N-1]);
  return 0;
}
0