結果
問題 | No.1364 [Renaming] Road to Cherry from Zelkova |
ユーザー | kotatsugame |
提出日時 | 2021-01-29 23:32:20 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,307 bytes |
コンパイル時間 | 919 ms |
コンパイル使用メモリ | 84,784 KB |
実行使用メモリ | 42,416 KB |
最終ジャッジ日時 | 2024-06-27 09:57:14 |
合計ジャッジ時間 | 14,065 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
17,476 KB |
testcase_01 | AC | 6 ms
17,364 KB |
testcase_02 | AC | 7 ms
17,832 KB |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | AC | 6 ms
17,212 KB |
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 | 81 ms
19,932 KB |
testcase_25 | AC | 223 ms
28,028 KB |
testcase_26 | AC | 331 ms
33,188 KB |
testcase_27 | AC | 237 ms
27,620 KB |
testcase_28 | AC | 154 ms
25,504 KB |
testcase_29 | AC | 230 ms
26,508 KB |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | AC | 180 ms
24,708 KB |
testcase_33 | AC | 309 ms
31,684 KB |
testcase_34 | AC | 297 ms
31,556 KB |
testcase_35 | AC | 305 ms
34,096 KB |
testcase_36 | AC | 297 ms
33,196 KB |
testcase_37 | AC | 183 ms
24,116 KB |
testcase_38 | AC | 245 ms
24,988 KB |
testcase_39 | AC | 245 ms
24,884 KB |
testcase_40 | AC | 242 ms
24,704 KB |
testcase_41 | AC | 243 ms
25,232 KB |
testcase_42 | AC | 245 ms
26,036 KB |
testcase_43 | AC | 130 ms
42,416 KB |
testcase_44 | AC | 98 ms
31,008 KB |
testcase_45 | AC | 126 ms
40,400 KB |
testcase_46 | AC | 12 ms
22,988 KB |
testcase_47 | AC | 5 ms
17,288 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])*e.second.second; } } cout<<ep[P[N]]<<endl; }