結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | kotatsugame |
提出日時 | 2021-01-29 23:34:21 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,289 bytes |
コンパイル時間 | 1,126 ms |
コンパイル使用メモリ | 83,796 KB |
実行使用メモリ | 42,892 KB |
最終ジャッジ日時 | 2024-06-27 09:58:31 |
合計ジャッジ時間 | 13,496 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 8 ms
18,744 KB |
testcase_01 | AC | 7 ms
18,200 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | AC | 85 ms
19,924 KB |
testcase_25 | AC | 229 ms
26,940 KB |
testcase_26 | AC | 361 ms
31,764 KB |
testcase_27 | AC | 251 ms
27,600 KB |
testcase_28 | AC | 159 ms
26,492 KB |
testcase_29 | AC | 243 ms
26,804 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 190 ms
24,340 KB |
testcase_33 | AC | 336 ms
30,444 KB |
testcase_34 | AC | 317 ms
32,436 KB |
testcase_35 | AC | 328 ms
33,932 KB |
testcase_36 | AC | 324 ms
33,176 KB |
testcase_37 | AC | 188 ms
24,684 KB |
testcase_38 | WA | - |
testcase_39 | WA | - |
testcase_40 | WA | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | AC | 138 ms
42,892 KB |
testcase_44 | AC | 101 ms
31,024 KB |
testcase_45 | AC | 132 ms
41,200 KB |
testcase_46 | AC | 13 ms
22,384 KB |
testcase_47 | AC | 7 ms
17,252 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:H[i]) { vis[e.first]=true; dp[e.first]+=dp[i]*e.second.second; ep[e.first]+=ep[i]+e.second.first*dp[i]; } } cout<<ep[P[N]]<<endl; }