結果

問題 No.1601 With Animals into Institute
ユーザー 👑 kmjpkmjp
提出日時 2021-07-11 11:20:37
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 387 ms / 3,000 ms
コード長 1,519 bytes
コンパイル時間 2,177 ms
コンパイル使用メモリ 208,456 KB
実行使用メモリ 20,960 KB
最終ジャッジ日時 2023-09-14 20:07:33
合計ジャッジ時間 10,416 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
11,556 KB
testcase_01 AC 4 ms
11,580 KB
testcase_02 AC 4 ms
11,628 KB
testcase_03 AC 8 ms
12,056 KB
testcase_04 AC 8 ms
11,836 KB
testcase_05 AC 8 ms
11,836 KB
testcase_06 AC 377 ms
20,796 KB
testcase_07 AC 380 ms
20,872 KB
testcase_08 AC 375 ms
20,888 KB
testcase_09 AC 376 ms
20,960 KB
testcase_10 AC 378 ms
20,944 KB
testcase_11 AC 385 ms
20,940 KB
testcase_12 AC 381 ms
20,780 KB
testcase_13 AC 386 ms
20,808 KB
testcase_14 AC 381 ms
20,884 KB
testcase_15 AC 387 ms
20,804 KB
testcase_16 AC 383 ms
20,940 KB
testcase_17 AC 386 ms
20,948 KB
testcase_18 AC 8 ms
11,880 KB
testcase_19 AC 8 ms
11,868 KB
testcase_20 AC 8 ms
11,852 KB
testcase_21 AC 8 ms
11,872 KB
testcase_22 AC 8 ms
11,864 KB
testcase_23 AC 8 ms
11,868 KB
testcase_24 AC 8 ms
12,068 KB
testcase_25 AC 8 ms
11,844 KB
testcase_26 AC 7 ms
11,864 KB
testcase_27 AC 4 ms
11,608 KB
testcase_28 AC 4 ms
11,576 KB
testcase_29 AC 4 ms
11,556 KB
testcase_30 AC 4 ms
11,556 KB
testcase_31 AC 4 ms
11,556 KB
testcase_32 AC 4 ms
11,572 KB
testcase_33 AC 4 ms
11,560 KB
testcase_34 AC 4 ms
11,752 KB
testcase_35 AC 4 ms
11,584 KB
testcase_36 AC 4 ms
11,752 KB
testcase_37 AC 4 ms
11,576 KB
testcase_38 AC 4 ms
11,576 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;
int A[202020],B[202020],C[202020],X[202020];
vector<pair<int,int>> E[202020];

ll dp[202020][2];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>A[i]>>B[i]>>C[i]>>X[i];
		A[i]--;
		B[i]--;
		E[A[i]].push_back({B[i],i});
		E[B[i]].push_back({A[i],i});
	}
	FOR(i,N) dp[i][0]=dp[i][1]=1LL<<60;
	dp[N-1][0]=0;
	priority_queue<pair<ll,int>> Q;
	Q.push({0,N-1});
	while(Q.size()) {
		ll co=-Q.top().first;
		int cur=Q.top().second%N;
		int did=Q.top().second/N;
		Q.pop();
		if(dp[cur][did]!=co) continue;
		FORR2(e,i,E[cur]) {
			int tar=did|X[i];
			if(dp[e][tar]>co+C[i]) {
				dp[e][tar]=co+C[i];
				Q.push({-dp[e][tar],tar*N+e});
			}
		}
	}
	FOR(i,N-1) cout<<dp[i][1]<<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