結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | kotatsugame |
提出日時 | 2021-01-30 13:33:38 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 439 ms / 2,500 ms |
コード長 | 4,307 bytes |
コンパイル時間 | 1,067 ms |
コンパイル使用メモリ | 83,356 KB |
実行使用メモリ | 42,448 KB |
最終ジャッジ日時 | 2024-06-28 01:38:17 |
合計ジャッジ時間 | 14,622 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
17,624 KB |
testcase_01 | AC | 7 ms
18,088 KB |
testcase_02 | AC | 7 ms
17,212 KB |
testcase_03 | AC | 7 ms
17,768 KB |
testcase_04 | AC | 6 ms
18,000 KB |
testcase_05 | AC | 7 ms
17,836 KB |
testcase_06 | AC | 6 ms
18,012 KB |
testcase_07 | AC | 7 ms
17,712 KB |
testcase_08 | AC | 20 ms
18,620 KB |
testcase_09 | AC | 13 ms
18,760 KB |
testcase_10 | AC | 21 ms
19,484 KB |
testcase_11 | AC | 19 ms
19,092 KB |
testcase_12 | AC | 22 ms
19,296 KB |
testcase_13 | AC | 253 ms
31,480 KB |
testcase_14 | AC | 332 ms
30,464 KB |
testcase_15 | AC | 332 ms
32,192 KB |
testcase_16 | AC | 238 ms
27,132 KB |
testcase_17 | AC | 122 ms
27,700 KB |
testcase_18 | AC | 428 ms
37,808 KB |
testcase_19 | AC | 428 ms
36,368 KB |
testcase_20 | AC | 439 ms
36,844 KB |
testcase_21 | AC | 430 ms
37,056 KB |
testcase_22 | AC | 431 ms
37,012 KB |
testcase_23 | AC | 96 ms
22,976 KB |
testcase_24 | AC | 85 ms
20,272 KB |
testcase_25 | AC | 235 ms
27,508 KB |
testcase_26 | AC | 371 ms
32,348 KB |
testcase_27 | AC | 260 ms
27,472 KB |
testcase_28 | AC | 166 ms
26,036 KB |
testcase_29 | AC | 246 ms
26,524 KB |
testcase_30 | AC | 176 ms
24,892 KB |
testcase_31 | AC | 120 ms
24,660 KB |
testcase_32 | AC | 188 ms
23,768 KB |
testcase_33 | AC | 340 ms
31,304 KB |
testcase_34 | AC | 324 ms
31,732 KB |
testcase_35 | AC | 344 ms
34,148 KB |
testcase_36 | AC | 338 ms
32,132 KB |
testcase_37 | AC | 190 ms
24,652 KB |
testcase_38 | AC | 251 ms
24,696 KB |
testcase_39 | AC | 254 ms
25,748 KB |
testcase_40 | AC | 253 ms
25,824 KB |
testcase_41 | AC | 253 ms
24,528 KB |
testcase_42 | AC | 253 ms
25,392 KB |
testcase_43 | AC | 137 ms
42,448 KB |
testcase_44 | AC | 103 ms
30,840 KB |
testcase_45 | AC | 133 ms
40,520 KB |
testcase_46 | AC | 13 ms
23,432 KB |
testcase_47 | AC | 7 ms
17,748 KB |
コンパイルメッセージ
a.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
ソースコード
#line 1 "a.cpp" #include<iostream> #include<vector> using namespace std; #line 3 "/home/kotatsugame/library/math/modint.cpp" #include<utility> template<int m> struct modint{ unsigned int x; constexpr modint()noexcept:x(){} template<typename T> constexpr modint(T x_)noexcept:x((x_%=m)<0?x_+m:x_){} constexpr unsigned int val()const noexcept{return x;} constexpr modint&operator++()noexcept{if(++x==m)x=0;return*this;} constexpr modint&operator--()noexcept{if(x==0)x=m;--x;return*this;} constexpr modint operator++(int)noexcept{modint res=*this;++*this;return res;} constexpr modint operator--(int)noexcept{modint res=*this;--*this;return res;} constexpr modint&operator+=(const modint&a)noexcept{x+=a.x;if(x>=m)x-=m;return*this;} constexpr modint&operator-=(const modint&a)noexcept{if(x<a.x)x+=m;x-=a.x;return*this;} constexpr modint&operator*=(const modint&a)noexcept{x=(unsigned long long)x*a.x%m;return*this;} constexpr modint&operator/=(const modint&a)noexcept{return*this*=a.inv();} constexpr modint operator+()const noexcept{return*this;} constexpr modint operator-()const noexcept{return modint()-*this;} constexpr modint pow(long long n)const noexcept { if(n<0)return pow(-n).inv(); modint x=*this,r=1; for(;n;x*=x,n>>=1)if(n&1)r*=x; return r; } constexpr modint inv()const noexcept { int s=x,t=m,x=1,u=0; while(t) { int k=s/t; s-=k*t; swap(s,t); x-=k*u; swap(x,u); } return modint(x); } friend constexpr modint operator+(const modint&a,const modint&b){return modint(a)+=b;} friend constexpr modint operator-(const modint&a,const modint&b){return modint(a)-=b;} friend constexpr modint operator*(const modint&a,const modint&b){return modint(a)*=b;} friend constexpr modint operator/(const modint&a,const modint&b){return modint(a)/=b;} friend constexpr bool operator==(const modint&a,const modint&b){return a.x==b.x;} friend constexpr bool operator!=(const modint&a,const modint&b){return a.x!=b.x;} friend ostream&operator<<(ostream&os,const modint&a){return os<<a.x;} friend istream&operator>>(istream&is,modint&a){long long v;is>>v;a=modint(v);return is;} }; #line 1 "/home/kotatsugame/library/graph/SCC.cpp" //Strongly Connected Components #line 3 "/home/kotatsugame/library/graph/SCC.cpp" struct SCC{ int n; vector<int>comp,order; vector<bool>used; vector<vector<int> >G,RG; SCC(int _n=0):n(_n),comp(_n,-1),used(_n,false),G(_n),RG(_n){} void add_edge(int from,int to) { G[from].push_back(to); RG[to].push_back(from); } void copy(const vector<vector<int> >&H) { for(int i=0;i<H.size();i++) { for(int j=0;j<H[i].size();j++) { G[i].push_back(H[i][j]); RG[H[i][j]].push_back(i); } } } int operator[](int u)const{return comp[u];} void dfs(int u) { used[u]=true; for(int i=0;i<G[u].size();i++)if(!used[G[u][i]])dfs(G[u][i]); order.push_back(u); } void rdfs(int u,int cnt) { comp[u]=cnt; for(int i=0;i<RG[u].size();i++)if(comp[RG[u][i]]==-1)rdfs(RG[u][i],cnt); } int build() { for(int i=0;i<n;i++)if(!used[i])dfs(i); int cnt=0; for(int i=n-1;i>=0;i--)if(comp[order[i]]==-1)rdfs(order[i],cnt++); return cnt; } int build(vector<vector<int> >&H) { int ret=build(); H.assign(ret,vector<int>()); for(int i=0;i<n;i++) { for(int j=0;j<G[i].size();j++) { if(comp[i]!=comp[G[i][j]]) H[comp[i]].push_back(comp[G[i][j]]); } } return ret; } }; #line 6 "a.cpp" using mint=modint<(int)1e9+7>; int N,M; vector<pair<int,pair<mint,mint> > >G[2<<17],H[2<<17]; int cnt[2<<17]; mint dp[2<<17],ep[2<<17]; bool vis[2<<17]; main() { cin>>N>>M; SCC P(N+1); for(int i=0;i<M;i++) { int u,v; mint l,a; cin>>u>>v>>l>>a; H[u].push_back(make_pair(v,make_pair(l,a))); P.add_edge(u,v); } int K=P.build(); for(int i=0;i<=N;i++)cnt[P[i]]++; for(int i=0;i<=N;i++)for(int j=0;j<H[i].size();j++) { G[P[i]].push_back(make_pair(P[H[i][j].first],H[i][j].second)); } if(P[0]>P[N]) { cout<<0<<endl; return 0; } dp[P[0]]=1; ep[P[0]]=0; vis[P[0]]=true; for(int i=P[0];i<=P[N];i++)if(vis[i]) { if(cnt[i]>1) { cout<<"INF"<<endl; return 0; } for(pair<int,pair<mint,mint> >e:G[i]) { vis[e.first]=true; dp[e.first]+=dp[i]*e.second.second; ep[e.first]+=(ep[i]+e.second.first*dp[i])*e.second.second; } } cout<<ep[P[N]]<<endl; }