結果

問題 No.1898 Battle and Exchange
ユーザー 👑 kmjpkmjp
提出日時 2022-04-09 00:59:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 663 ms / 5,000 ms
コード長 1,802 bytes
コンパイル時間 2,519 ms
コンパイル使用メモリ 209,904 KB
実行使用メモリ 15,460 KB
最終ジャッジ日時 2023-08-19 03:20:25
合計ジャッジ時間 24,271 ms
ジャッジサーバーID
(参考情報)
judge9 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
10,004 KB
testcase_01 AC 6 ms
10,032 KB
testcase_02 AC 6 ms
10,080 KB
testcase_03 AC 6 ms
9,984 KB
testcase_04 AC 6 ms
9,992 KB
testcase_05 AC 6 ms
10,000 KB
testcase_06 AC 7 ms
10,064 KB
testcase_07 AC 7 ms
10,020 KB
testcase_08 AC 6 ms
9,984 KB
testcase_09 AC 14 ms
10,340 KB
testcase_10 AC 6 ms
10,040 KB
testcase_11 AC 6 ms
10,044 KB
testcase_12 AC 6 ms
10,312 KB
testcase_13 AC 6 ms
9,976 KB
testcase_14 AC 6 ms
10,024 KB
testcase_15 AC 6 ms
9,988 KB
testcase_16 AC 6 ms
10,012 KB
testcase_17 AC 12 ms
10,236 KB
testcase_18 AC 49 ms
10,932 KB
testcase_19 AC 89 ms
11,368 KB
testcase_20 AC 51 ms
11,448 KB
testcase_21 AC 281 ms
13,548 KB
testcase_22 AC 6 ms
10,040 KB
testcase_23 AC 6 ms
10,060 KB
testcase_24 AC 6 ms
10,052 KB
testcase_25 AC 6 ms
10,020 KB
testcase_26 AC 6 ms
10,040 KB
testcase_27 AC 8 ms
10,252 KB
testcase_28 AC 8 ms
10,292 KB
testcase_29 AC 13 ms
10,504 KB
testcase_30 AC 7 ms
10,036 KB
testcase_31 AC 6 ms
10,044 KB
testcase_32 AC 59 ms
11,292 KB
testcase_33 AC 144 ms
12,488 KB
testcase_34 AC 60 ms
11,132 KB
testcase_35 AC 100 ms
11,956 KB
testcase_36 AC 74 ms
11,504 KB
testcase_37 AC 35 ms
10,684 KB
testcase_38 AC 663 ms
15,460 KB
testcase_39 AC 123 ms
14,372 KB
testcase_40 AC 571 ms
14,920 KB
testcase_41 AC 83 ms
14,084 KB
testcase_42 AC 14 ms
10,356 KB
testcase_43 AC 84 ms
12,928 KB
testcase_44 AC 6 ms
9,988 KB
testcase_45 AC 27 ms
10,324 KB
testcase_46 AC 99 ms
11,472 KB
testcase_47 AC 19 ms
10,300 KB
testcase_48 AC 18 ms
10,644 KB
testcase_49 AC 7 ms
10,160 KB
testcase_50 AC 8 ms
10,284 KB
testcase_51 AC 8 ms
10,164 KB
testcase_52 AC 9 ms
10,276 KB
testcase_53 AC 28 ms
11,192 KB
testcase_54 AC 29 ms
11,312 KB
testcase_55 AC 56 ms
11,288 KB
testcase_56 AC 34 ms
11,444 KB
testcase_57 AC 590 ms
13,952 KB
testcase_58 AC 344 ms
14,204 KB
testcase_59 AC 299 ms
13,916 KB
testcase_60 AC 413 ms
13,928 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