結果
| 問題 |
No.1364 [Renaming] Road to Cherry from Zelkova
|
| コンテスト | |
| ユーザー |
moririn2528_c
|
| 提出日時 | 2021-01-23 15:17:18 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 336 ms / 2,500 ms |
| コード長 | 2,731 bytes |
| コンパイル時間 | 1,558 ms |
| コンパイル使用メモリ | 121,612 KB |
| 実行使用メモリ | 13,824 KB |
| 最終ジャッジ日時 | 2024-12-30 20:40:35 |
| 合計ジャッジ時間 | 12,031 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
#include<cassert>
#include<set>
#include<complex>
#include<numeric>
#include<functional>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;
void array_show(int *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
if(vec_n==-1)vec_n=vec_s.size();
for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
namespace sol{
typedef tuple<LL,LL,LL> T;
vector<vector<T>> path;
LL cnt[220000][2];
bool used[220000];
int deg[220000];
void dfs(int pos){
if(used[pos])return;
used[pos]=true;
int a,b,c;
for(auto node:path[pos]){
tie(a,b,c)=node;
dfs(a);
}
}
void solve(){
int n,m;
int i,j,k;
LL a,b,c,d;
cin>>n>>m;
n++;
path.assign(n,vector<T>());
for(i=0;i<m;i++){
cin>>a>>b>>c>>d;
path[a].push_back(make_tuple(b,c,d));
}
dfs(0);
for(i=0;i<n;i++){
if(!used[i]){
path[i].clear();
}
for(auto node:path[i]){
tie(a,b,c)=node;
deg[a]++;
}
}
if(!used[n-1]){
cout<<0<<endl;
return;
}
if(deg[0]){
cout<<"INF"<<endl;
return;
}
queue<int> q1;
q1.push(0);
cnt[0][1]=1;
while(!q1.empty()){
a=q1.front();q1.pop();
cnt[a][0]%=MAX,cnt[a][1]%=MAX;
if(a==n-1){
cout<<cnt[a][0]<<endl;
return;
}
for(auto node:path[a]){
tie(b,c,d)=node;
cnt[b][1]+=cnt[a][1]*d%MAX;
cnt[b][0]+=(cnt[a][0]*d+cnt[a][1]*c%MAX*d)%MAX;
deg[b]--;
if(deg[b]==0)q1.push(b);
}
}
cout<<"INF"<<endl;
}
}
int main(){
sol::solve();
}
moririn2528_c