結果

問題 No.1364 [Renaming] Road to Cherry from Zelkova
ユーザー kotatsugamekotatsugame
提出日時 2021-01-30 13:33:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 427 ms / 2,500 ms
コード長 4,307 bytes
コンパイル時間 911 ms
コンパイル使用メモリ 84,036 KB
実行使用メモリ 41,788 KB
最終ジャッジ日時 2023-09-10 10:12:42
合計ジャッジ時間 15,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
16,892 KB
testcase_01 AC 7 ms
16,928 KB
testcase_02 AC 8 ms
16,876 KB
testcase_03 AC 7 ms
16,928 KB
testcase_04 AC 8 ms
16,968 KB
testcase_05 AC 7 ms
16,956 KB
testcase_06 AC 7 ms
16,952 KB
testcase_07 AC 7 ms
16,944 KB
testcase_08 AC 21 ms
18,236 KB
testcase_09 AC 13 ms
17,288 KB
testcase_10 AC 21 ms
17,832 KB
testcase_11 AC 19 ms
17,732 KB
testcase_12 AC 22 ms
17,852 KB
testcase_13 AC 249 ms
30,612 KB
testcase_14 AC 338 ms
30,060 KB
testcase_15 AC 333 ms
31,552 KB
testcase_16 AC 233 ms
26,696 KB
testcase_17 AC 121 ms
27,116 KB
testcase_18 AC 427 ms
35,940 KB
testcase_19 AC 423 ms
36,024 KB
testcase_20 AC 422 ms
36,040 KB
testcase_21 AC 422 ms
36,128 KB
testcase_22 AC 426 ms
36,124 KB
testcase_23 AC 89 ms
22,608 KB
testcase_24 AC 81 ms
19,140 KB
testcase_25 AC 225 ms
26,640 KB
testcase_26 AC 371 ms
31,344 KB
testcase_27 AC 254 ms
26,484 KB
testcase_28 AC 164 ms
24,716 KB
testcase_29 AC 236 ms
25,588 KB
testcase_30 AC 170 ms
24,656 KB
testcase_31 AC 118 ms
23,176 KB
testcase_32 AC 184 ms
23,420 KB
testcase_33 AC 338 ms
29,596 KB
testcase_34 AC 331 ms
31,224 KB
testcase_35 AC 344 ms
33,176 KB
testcase_36 AC 335 ms
31,980 KB
testcase_37 AC 178 ms
23,768 KB
testcase_38 AC 236 ms
24,588 KB
testcase_39 AC 249 ms
24,748 KB
testcase_40 AC 237 ms
24,572 KB
testcase_41 AC 240 ms
24,412 KB
testcase_42 AC 239 ms
24,688 KB
testcase_43 AC 134 ms
41,788 KB
testcase_44 AC 99 ms
30,496 KB
testcase_45 AC 129 ms
39,896 KB
testcase_46 AC 12 ms
22,356 KB
testcase_47 AC 8 ms
17,100 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
a.cpp:12:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]

ソースコード

diff #

#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;
}
0