結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー |
👑 ![]() |
提出日時 | 2021-01-22 23:47:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 213 ms / 2,500 ms |
コード長 | 1,350 bytes |
コンパイル時間 | 2,306 ms |
コンパイル使用メモリ | 202,984 KB |
最終ジャッジ日時 | 2025-01-18 06:32:57 |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:24:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 24 | scanf("%d%d",&N,&n); N++; | ~~~~~^~~~~~~~~~~~~~ main.cpp:27:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 27 | int u,v,d,t; scanf("%d%d%d%d",&u,&v,&d,&t); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#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];vector<int> rE[100001];bool reach[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});rE[v].push_back(u);I[v]++;}{queue<int> Q;rep(i,N) reach[i]=false;reach[0]=true; Q.push(0);while(Q.size()){int p=Q.front(); Q.pop();for(Edge e:E[p]) if(!reach[e.to]) { reach[e.to]=true; Q.push(e.to); }}rep(i,N) if(!reach[i]){ for(Edge e:E[i]) I[e.to]--; E[i].clear(); }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;}