結果

問題 No.1898 Battle and Exchange
ユーザー msm1993msm1993
提出日時 2022-12-16 17:29:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 411 ms / 5,000 ms
コード長 1,802 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 180,732 KB
実行使用メモリ 15,180 KB
最終ジャッジ日時 2024-04-27 18:04:45
合計ジャッジ時間 16,363 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
10,180 KB
testcase_01 AC 5 ms
11,076 KB
testcase_02 AC 5 ms
10,184 KB
testcase_03 AC 5 ms
11,320 KB
testcase_04 AC 5 ms
10,436 KB
testcase_05 AC 5 ms
11,108 KB
testcase_06 AC 5 ms
11,408 KB
testcase_07 AC 5 ms
11,288 KB
testcase_08 AC 5 ms
11,336 KB
testcase_09 AC 12 ms
10,820 KB
testcase_10 AC 6 ms
8,960 KB
testcase_11 AC 6 ms
9,088 KB
testcase_12 AC 7 ms
8,960 KB
testcase_13 AC 6 ms
9,216 KB
testcase_14 AC 7 ms
9,088 KB
testcase_15 AC 6 ms
9,088 KB
testcase_16 AC 7 ms
9,088 KB
testcase_17 AC 11 ms
9,216 KB
testcase_18 AC 43 ms
11,204 KB
testcase_19 AC 79 ms
10,496 KB
testcase_20 AC 42 ms
12,556 KB
testcase_21 AC 164 ms
13,056 KB
testcase_22 AC 6 ms
10,184 KB
testcase_23 AC 5 ms
11,388 KB
testcase_24 AC 5 ms
10,816 KB
testcase_25 AC 5 ms
10,176 KB
testcase_26 AC 5 ms
10,436 KB
testcase_27 AC 6 ms
11,392 KB
testcase_28 AC 6 ms
10,820 KB
testcase_29 AC 11 ms
11,444 KB
testcase_30 AC 6 ms
9,216 KB
testcase_31 AC 6 ms
9,216 KB
testcase_32 AC 52 ms
10,368 KB
testcase_33 AC 114 ms
13,148 KB
testcase_34 AC 53 ms
10,240 KB
testcase_35 AC 83 ms
12,100 KB
testcase_36 AC 63 ms
10,624 KB
testcase_37 AC 31 ms
11,900 KB
testcase_38 AC 411 ms
14,808 KB
testcase_39 AC 98 ms
14,836 KB
testcase_40 AC 352 ms
15,180 KB
testcase_41 AC 72 ms
14,772 KB
testcase_42 AC 12 ms
11,492 KB
testcase_43 AC 74 ms
12,032 KB
testcase_44 AC 5 ms
10,564 KB
testcase_45 AC 24 ms
11,632 KB
testcase_46 AC 84 ms
10,496 KB
testcase_47 AC 16 ms
11,244 KB
testcase_48 AC 17 ms
9,600 KB
testcase_49 AC 7 ms
10,948 KB
testcase_50 AC 6 ms
10,952 KB
testcase_51 AC 7 ms
11,352 KB
testcase_52 AC 9 ms
10,440 KB
testcase_53 AC 26 ms
9,984 KB
testcase_54 AC 25 ms
11,464 KB
testcase_55 AC 51 ms
10,240 KB
testcase_56 AC 29 ms
12,580 KB
testcase_57 AC 336 ms
13,312 KB
testcase_58 AC 193 ms
14,272 KB
testcase_59 AC 181 ms
14,384 KB
testcase_60 AC 223 ms
14,152 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;
vector<int> E[202020];
int A[202020],B[202020],C[202020];
int vis[202020];

int hoge(int CA) {
	int CB=1,CC=1;
	ZERO(vis);
	
	//初手だけ確認
	if(CA+CB+CC<=A[0]+B[0]+C[0]) return 0;
	int add=max({0,A[0]-1,B[0]-1,C[0]-1});
	
	int ok=0;
	FORR(e,E[0]) if(CA+CB+CC+add>A[e]+B[e]+C[e]) ok=1;
	if(ok==0) return 0;
	priority_queue<pair<int,int>> Q;
	vis[0]=1;
	Q.push({-A[0]-B[0]-C[0],0});
	while(Q.size()) {
		int cur=Q.top().second;
		Q.pop();
		if(A[cur]+B[cur]+C[cur]>=CA+CB+CC) return 0;
		if(cur==N-1) return 1;
		vector<int> V={CA,CB,CC,A[cur],B[cur],C[cur]};
		sort(ALL(V));
		CA=V[5];
		CB=V[4];
		CC=V[3];
		FORR(e,E[cur]) if(vis[e]==0) {
			Q.push({-A[e]-B[e]-C[e],e});
			vis[e]=1;
		}
	}
	return 0;
	
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>x>>y;
		E[x-1].push_back(y-1);
		E[y-1].push_back(x-1);
	}
	FOR(i,N) cin>>A[i]>>B[i]>>C[i];
	int ret=1<<30;
	for(i=29;i>=0;i--) if(hoge(ret-(1<<i))) ret-=1<<i;
	cout<<ret<<" "<<1<<" "<<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