結果

問題 No.1898 Battle and Exchange
ユーザー 👑 kmjpkmjp
提出日時 2022-04-09 00:59:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 651 ms / 5,000 ms
コード長 1,802 bytes
コンパイル時間 2,512 ms
コンパイル使用メモリ 212,340 KB
実行使用メモリ 14,684 KB
最終ジャッジ日時 2024-05-06 10:27:45
合計ジャッジ時間 18,771 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
8,960 KB
testcase_01 AC 7 ms
8,960 KB
testcase_02 AC 7 ms
8,832 KB
testcase_03 AC 7 ms
8,832 KB
testcase_04 AC 7 ms
9,088 KB
testcase_05 AC 7 ms
9,088 KB
testcase_06 AC 8 ms
9,088 KB
testcase_07 AC 7 ms
9,088 KB
testcase_08 AC 7 ms
8,960 KB
testcase_09 AC 15 ms
9,344 KB
testcase_10 AC 7 ms
9,088 KB
testcase_11 AC 7 ms
9,088 KB
testcase_12 AC 7 ms
9,088 KB
testcase_13 AC 7 ms
8,960 KB
testcase_14 AC 8 ms
8,960 KB
testcase_15 AC 7 ms
8,960 KB
testcase_16 AC 7 ms
8,960 KB
testcase_17 AC 14 ms
9,088 KB
testcase_18 AC 50 ms
9,984 KB
testcase_19 AC 85 ms
10,496 KB
testcase_20 AC 51 ms
10,624 KB
testcase_21 AC 216 ms
12,800 KB
testcase_22 AC 8 ms
8,960 KB
testcase_23 AC 7 ms
8,960 KB
testcase_24 AC 7 ms
9,088 KB
testcase_25 AC 8 ms
9,088 KB
testcase_26 AC 7 ms
9,088 KB
testcase_27 AC 9 ms
9,216 KB
testcase_28 AC 9 ms
9,088 KB
testcase_29 AC 14 ms
9,480 KB
testcase_30 AC 8 ms
9,088 KB
testcase_31 AC 7 ms
8,960 KB
testcase_32 AC 60 ms
10,368 KB
testcase_33 AC 149 ms
11,520 KB
testcase_34 AC 60 ms
10,112 KB
testcase_35 AC 105 ms
10,880 KB
testcase_36 AC 74 ms
10,624 KB
testcase_37 AC 38 ms
9,600 KB
testcase_38 AC 651 ms
14,684 KB
testcase_39 AC 122 ms
13,524 KB
testcase_40 AC 495 ms
14,200 KB
testcase_41 AC 87 ms
13,388 KB
testcase_42 AC 16 ms
9,088 KB
testcase_43 AC 85 ms
12,288 KB
testcase_44 AC 7 ms
8,960 KB
testcase_45 AC 28 ms
9,216 KB
testcase_46 AC 97 ms
10,368 KB
testcase_47 AC 20 ms
9,216 KB
testcase_48 AC 20 ms
9,600 KB
testcase_49 AC 9 ms
9,216 KB
testcase_50 AC 9 ms
9,088 KB
testcase_51 AC 10 ms
9,088 KB
testcase_52 AC 11 ms
9,344 KB
testcase_53 AC 30 ms
10,112 KB
testcase_54 AC 31 ms
10,368 KB
testcase_55 AC 59 ms
10,240 KB
testcase_56 AC 35 ms
10,496 KB
testcase_57 AC 565 ms
13,184 KB
testcase_58 AC 343 ms
13,312 KB
testcase_59 AC 270 ms
13,312 KB
testcase_60 AC 337 ms
13,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;
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