結果

問題 No.2739 Time is money
ユーザー 👑 kmjpkmjp
提出日時 2024-04-20 22:46:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 183 ms / 2,000 ms
コード長 1,553 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 204,504 KB
実行使用メモリ 18,304 KB
最終ジャッジ日時 2024-04-20 22:46:17
合計ジャッジ時間 6,367 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
8,320 KB
testcase_01 AC 3 ms
8,320 KB
testcase_02 AC 68 ms
14,208 KB
testcase_03 AC 148 ms
17,208 KB
testcase_04 AC 67 ms
13,740 KB
testcase_05 AC 97 ms
14,420 KB
testcase_06 AC 148 ms
17,024 KB
testcase_07 AC 182 ms
18,176 KB
testcase_08 AC 183 ms
18,176 KB
testcase_09 AC 176 ms
18,136 KB
testcase_10 AC 121 ms
17,920 KB
testcase_11 AC 173 ms
18,168 KB
testcase_12 AC 128 ms
15,872 KB
testcase_13 AC 142 ms
16,128 KB
testcase_14 AC 129 ms
16,068 KB
testcase_15 AC 101 ms
17,200 KB
testcase_16 AC 108 ms
16,480 KB
testcase_17 AC 176 ms
18,304 KB
testcase_18 AC 169 ms
18,296 KB
testcase_19 AC 115 ms
17,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;}
//-------------------------------------------------------

int N,M,X;
vector<pair<int,pair<int,int>>> E[202020];
ll dp[202020];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M>>X;
	FOR(i,M) {
		cin>>x>>y>>k>>j;
		x--,y--;
		E[x].push_back({y,{j,k}});
		E[y].push_back({x,{j,k}});
	}
	FOR(i,N) dp[i]=1LL<<60;
	dp[0]=0;
	priority_queue<pair<ll,int>> Q;
	Q.push({0,0});
	while(Q.size()) {
		ll co=-Q.top().first;
		int cur=Q.top().second;
		Q.pop();
		if(dp[cur]!=co) continue;
		ll a=co/1000000;
		ll b=co%1000000;
		FORR2(e,c,E[cur]) {
			ll na=a+c.first;
			ll nb=b+c.second;
			na+=nb/X;
			nb%=X;
			ll v=na*1000000+nb;
			if(chmin(dp[e],v)) Q.push({-dp[e],e});
		}
	}
	
	ll ret=dp[N-1];
	if(ret==1LL<<60) {
		cout<<-1<<endl;
	}
	else {
		ret=ret/1000000+(ret%1000000>0);
		cout<<ret<<endl;
	}
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}
0