結果

問題 No.1898 Battle and Exchange
ユーザー 沙耶花沙耶花
提出日時 2022-04-08 22:18:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 621 ms / 5,000 ms
コード長 1,533 bytes
コンパイル時間 5,999 ms
コンパイル使用メモリ 268,564 KB
実行使用メモリ 12,824 KB
最終ジャッジ日時 2023-08-19 00:48:54
合計ジャッジ時間 27,465 ms
ジャッジサーバーID
(参考情報)
judge9 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 3 ms
4,380 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 13 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 3 ms
4,380 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 22 ms
4,380 KB
testcase_18 AC 108 ms
5,120 KB
testcase_19 AC 167 ms
5,868 KB
testcase_20 AC 182 ms
6,120 KB
testcase_21 AC 498 ms
10,336 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 5 ms
4,376 KB
testcase_28 AC 5 ms
4,376 KB
testcase_29 AC 13 ms
4,376 KB
testcase_30 AC 2 ms
4,380 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 78 ms
5,736 KB
testcase_33 AC 104 ms
7,880 KB
testcase_34 AC 66 ms
5,208 KB
testcase_35 AC 122 ms
6,596 KB
testcase_36 AC 64 ms
6,064 KB
testcase_37 AC 59 ms
4,396 KB
testcase_38 AC 621 ms
12,824 KB
testcase_39 AC 483 ms
10,732 KB
testcase_40 AC 548 ms
11,444 KB
testcase_41 AC 447 ms
10,336 KB
testcase_42 AC 18 ms
4,380 KB
testcase_43 AC 336 ms
8,980 KB
testcase_44 AC 2 ms
4,376 KB
testcase_45 AC 36 ms
4,384 KB
testcase_46 AC 159 ms
5,800 KB
testcase_47 AC 22 ms
4,380 KB
testcase_48 AC 54 ms
4,380 KB
testcase_49 AC 5 ms
4,376 KB
testcase_50 AC 5 ms
4,376 KB
testcase_51 AC 4 ms
4,376 KB
testcase_52 AC 7 ms
4,380 KB
testcase_53 AC 53 ms
4,872 KB
testcase_54 AC 38 ms
4,864 KB
testcase_55 AC 81 ms
4,832 KB
testcase_56 AC 77 ms
5,032 KB
testcase_57 AC 386 ms
11,112 KB
testcase_58 AC 569 ms
11,016 KB
testcase_59 AC 547 ms
11,096 KB
testcase_60 AC 556 ms
11,360 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