結果

問題 No.1898 Battle and Exchange
ユーザー 👑 potato167potato167
提出日時 2022-04-08 22:22:09
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,019 ms / 5,000 ms
コード長 2,289 bytes
コンパイル時間 2,443 ms
コンパイル使用メモリ 221,792 KB
実行使用メモリ 15,556 KB
最終ジャッジ日時 2023-08-19 00:52:25
合計ジャッジ時間 24,371 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 21 ms
4,380 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 2 ms
4,380 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 36 ms
4,376 KB
testcase_18 AC 174 ms
5,692 KB
testcase_19 AC 265 ms
6,836 KB
testcase_20 AC 285 ms
7,152 KB
testcase_21 AC 797 ms
13,384 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,376 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 AC 4 ms
4,376 KB
testcase_28 AC 4 ms
4,376 KB
testcase_29 AC 9 ms
4,380 KB
testcase_30 AC 2 ms
4,376 KB
testcase_31 AC 2 ms
4,376 KB
testcase_32 AC 163 ms
6,632 KB
testcase_33 AC 184 ms
9,540 KB
testcase_34 AC 133 ms
6,256 KB
testcase_35 AC 217 ms
8,104 KB
testcase_36 AC 128 ms
7,496 KB
testcase_37 AC 94 ms
4,556 KB
testcase_38 AC 1,019 ms
15,556 KB
testcase_39 AC 771 ms
13,036 KB
testcase_40 AC 899 ms
14,340 KB
testcase_41 AC 710 ms
12,616 KB
testcase_42 AC 28 ms
4,380 KB
testcase_43 AC 534 ms
10,640 KB
testcase_44 AC 2 ms
4,380 KB
testcase_45 AC 56 ms
4,380 KB
testcase_46 AC 244 ms
7,020 KB
testcase_47 AC 32 ms
4,376 KB
testcase_48 AC 77 ms
4,376 KB
testcase_49 AC 5 ms
4,380 KB
testcase_50 AC 4 ms
4,380 KB
testcase_51 AC 5 ms
4,380 KB
testcase_52 AC 5 ms
4,376 KB
testcase_53 AC 60 ms
4,752 KB
testcase_54 AC 30 ms
4,804 KB
testcase_55 AC 97 ms
4,888 KB
testcase_56 AC 83 ms
4,864 KB
testcase_57 AC 590 ms
14,408 KB
testcase_58 AC 919 ms
14,468 KB
testcase_59 AC 939 ms
14,356 KB
testcase_60 AC 913 ms
14,480 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
const ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
#define all(p) p.begin(),p.end()
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}
template<class T> void vec_out(vector<T> &p){for(int i=0;i<(int)(p.size());i++){if(i) cout<<" ";cout<<p[i];}cout<<"\n";}

ll S(vector<int> &p){
	int ans=0;
	for(auto x:p) ans+=x;
	return ans;
}

vector<int> f(vector<int> p,vector<int> q){
	for(auto x:q) p.push_back(x);
	Sore(p);
	p.resize(3);
	return p;
}

void solve();
// oddloop
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int t=1;
	//cin>>t;
	rep(i,t) solve();
}

void solve(){
	int N,M;
	cin>>N>>M;
	vector<vector<int>> G(N);
	rep(i,M){
		int u,v;
		cin>>u>>v;
		u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	vector<vector<int>> A(N,vector<int>(3));
	rep(i,N) rep(j,3) cin>>A[i][j];
	So(A[0]);
	int l=S(A[0])-2,r=INF/2;
	while(r-l>1){
		int med=(r+l)/2;
		vector<int> have={1,1,med};
		vector<int> seen(N);
		seen[0]=1;
		_pq<pair<int,int>> pq;
		pq.push({0,0});
		int J=1;
		while(!pq.empty()){
			if(S(have)<=pq.top().first) break;
			int ind,v;
			tie(v,ind)=pq.top();
			if(J==-1) have=f(have,A[ind]);
			else if(J==0){
				have=f({1,1,med},A[0]);
				have=f(have,A[ind]);
				J=-1;
			}else{
				have[0]=A[0][2];
				J=0;
			}
			pq.pop();
			seen[ind]=2;
			for(auto x:G[ind]){
				if(seen[x]==0) pq.push({S(A[x]),x}),seen[x]=1;
			}
		}
		if(seen[N-1]==2) r=med;
		else l=med;
	}
	cout<<"1 1 "<<r<<"\n";
}

0