結果

問題 No.1898 Battle and Exchange
ユーザー 沙耶花沙耶花
提出日時 2022-04-08 22:18:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 854 ms / 5,000 ms
コード長 1,533 bytes
コンパイル時間 4,509 ms
コンパイル使用メモリ 271,744 KB
実行使用メモリ 12,628 KB
最終ジャッジ日時 2024-05-06 07:51:24
合計ジャッジ時間 24,068 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 16 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 24 ms
5,376 KB
testcase_18 AC 114 ms
5,376 KB
testcase_19 AC 172 ms
6,016 KB
testcase_20 AC 193 ms
6,528 KB
testcase_21 AC 574 ms
10,496 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 3 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 6 ms
5,376 KB
testcase_28 AC 6 ms
5,376 KB
testcase_29 AC 15 ms
5,376 KB
testcase_30 AC 3 ms
5,376 KB
testcase_31 AC 2 ms
5,376 KB
testcase_32 AC 92 ms
5,888 KB
testcase_33 AC 121 ms
7,936 KB
testcase_34 AC 74 ms
5,760 KB
testcase_35 AC 121 ms
6,912 KB
testcase_36 AC 71 ms
6,528 KB
testcase_37 AC 60 ms
5,376 KB
testcase_38 AC 854 ms
12,628 KB
testcase_39 AC 615 ms
11,036 KB
testcase_40 AC 694 ms
11,912 KB
testcase_41 AC 532 ms
10,452 KB
testcase_42 AC 19 ms
5,376 KB
testcase_43 AC 365 ms
8,832 KB
testcase_44 AC 2 ms
5,376 KB
testcase_45 AC 37 ms
5,376 KB
testcase_46 AC 163 ms
6,016 KB
testcase_47 AC 24 ms
5,376 KB
testcase_48 AC 57 ms
5,376 KB
testcase_49 AC 5 ms
5,376 KB
testcase_50 AC 5 ms
5,376 KB
testcase_51 AC 5 ms
5,376 KB
testcase_52 AC 9 ms
5,376 KB
testcase_53 AC 57 ms
5,376 KB
testcase_54 AC 42 ms
5,376 KB
testcase_55 AC 85 ms
5,376 KB
testcase_56 AC 79 ms
5,376 KB
testcase_57 AC 542 ms
11,264 KB
testcase_58 AC 737 ms
11,392 KB
testcase_59 AC 731 ms
11,360 KB
testcase_60 AC 722 ms
11,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define Inf 1000000001


int main(){
	
	int n,m;
	cin>>n>>m;
	
	vector<vector<int>> E(n);
	rep(i,m){
		int u,v;
		scanf("%d %d",&u,&v);
		u--,v--;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	
	vector<long long> a(n),b(n),c(n);
	rep(i,n)scanf("%lld %lld %lld",&a[i],&b[i],&c[i]);
	
	long long ok = Inf,ng = a[0]+b[0]+c[0];
	while(ok-ng>1){
		int mid  =(ok+ng)/2;
	//	cout<<mid<<endl;
		{
			bool f = false;
			rep(i,E[0].size()){
				int to = E[0][i];
				if(a[to]+b[to]+c[to] < mid - 1 + max({a[0],b[0],c[0]})){
					f = true;
					break;
				}
			}
			if(!f){
				ng = mid;
				continue;
			}
		}
		//cout<<mid<<endl;
		vector<bool> f(n,false);
		f[0] = true;
		priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> Q;
		Q.emplace(0,0);
		vector<int> t(3,1);
		t[0] = mid-2;
		while(Q.size()>0){
			int D = Q.top().first;
			
			int u = Q.top().second;
			if(D >= t[0]+t[1]+t[2])break;
			Q.pop();
			
			t.push_back(a[u]);
			t.push_back(b[u]);
			t.push_back(c[u]);
			sort(t.rbegin(),t.rend());
			rep(i,3)t.pop_back();
			rep(i,E[u].size()){
				int v = E[u][i];
				if(f[v])continue;
				f[v] = true;
				Q.emplace(a[v] + b[v] + c[v],v);
			}
		}
		while(Q.size()>0){
			int u = Q.top().second;
			f[u]=  false;
			Q.pop();
		}
		if(f[n-1])ok = mid;
		else ng = mid;
	}
	cout<<1<<' '<<1<<' '<<ok-2<<endl;
		
	return 0;
}
0