結果

問題 No.1473 おでぶなおばけさん
ユーザー tanimani364tanimani364
提出日時 2021-04-11 14:34:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 297 ms / 2,000 ms
コード長 2,580 bytes
コンパイル時間 3,075 ms
コンパイル使用メモリ 212,792 KB
実行使用メモリ 10,244 KB
最終ジャッジ日時 2023-09-09 16:59:57
合計ジャッジ時間 10,218 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 166 ms
9,564 KB
testcase_03 AC 95 ms
8,580 KB
testcase_04 AC 92 ms
6,644 KB
testcase_05 AC 33 ms
4,380 KB
testcase_06 AC 177 ms
9,052 KB
testcase_07 AC 165 ms
9,384 KB
testcase_08 AC 297 ms
9,464 KB
testcase_09 AC 133 ms
9,388 KB
testcase_10 AC 48 ms
5,332 KB
testcase_11 AC 61 ms
6,340 KB
testcase_12 AC 41 ms
5,724 KB
testcase_13 AC 28 ms
4,748 KB
testcase_14 AC 21 ms
4,376 KB
testcase_15 AC 49 ms
5,496 KB
testcase_16 AC 40 ms
4,888 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 8 ms
4,376 KB
testcase_19 AC 52 ms
5,872 KB
testcase_20 AC 65 ms
7,788 KB
testcase_21 AC 81 ms
7,440 KB
testcase_22 AC 59 ms
9,304 KB
testcase_23 AC 49 ms
7,984 KB
testcase_24 AC 46 ms
8,260 KB
testcase_25 AC 272 ms
9,356 KB
testcase_26 AC 237 ms
9,400 KB
testcase_27 AC 46 ms
5,104 KB
testcase_28 AC 223 ms
9,304 KB
testcase_29 AC 134 ms
7,780 KB
testcase_30 AC 161 ms
8,528 KB
testcase_31 AC 101 ms
9,564 KB
testcase_32 AC 104 ms
9,324 KB
testcase_33 AC 63 ms
8,140 KB
testcase_34 AC 37 ms
5,768 KB
testcase_35 AC 35 ms
5,616 KB
testcase_36 AC 99 ms
6,772 KB
testcase_37 AC 173 ms
7,816 KB
testcase_38 AC 19 ms
4,376 KB
testcase_39 AC 46 ms
4,888 KB
testcase_40 AC 39 ms
4,960 KB
testcase_41 AC 41 ms
4,888 KB
testcase_42 AC 41 ms
5,036 KB
testcase_43 AC 43 ms
6,872 KB
testcase_44 AC 43 ms
7,048 KB
testcase_45 AC 43 ms
6,880 KB
testcase_46 AC 73 ms
9,008 KB
testcase_47 AC 94 ms
10,244 KB
testcase_48 AC 85 ms
9,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include<boost/multiprecision/cpp_int.hpp>
//#include<boost/multiprecision/cpp_dec_float.hpp>
//#include <atcoder/all>
#define rep(i, a) for (int i = (int)0; i < (int)a; ++i)
#define rrep(i, a) for (int i = (int)a - 1; i >= 0; --i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define RREP(i, a, b) for (int i = (int)a - 1; i >= b; --i)
#define repl(i, a) for (ll i = (ll)0; i < (ll)a; ++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll
#define fi first
#define se second
using ll = long long;
constexpr ll mod = 1e9 + 7;
constexpr ll mod_998244353 = 998244353;
constexpr ll INF = 1LL << 60;

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

//using lll=boost::multiprecision::cpp_int;
//using Double=boost::multiprecision::number<boost::multiprecision::cpp_dec_float<128>>;//仮数部が1024桁
template <class T>
inline bool chmin(T &a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
template <class T>
inline bool chmax(T &a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}

ll mypow(ll x, ll n, const ll &p = -1)
{ //x^nをmodで割った余り

	if (p != -1)
	{
		x =(x%p+p)%p;
	}
	ll ret = 1;
	while (n > 0)
	{
		if (n & 1)
		{
			if (p != -1)
				ret = (ret * x) % p;
			else
				ret *= x;
		}
		if (p != -1)
			x = (x * x) % p;
		else
			x *= x;
		n >>= 1;
	}
	return ret;
}

using namespace std;
//using namespace atcoder;
struct edge{
	int to,cost;
	edge(int a,int b):to(a),cost(b){}
};

void solve()
{	
	int n,m;
	cin>>n>>m;
	vector<vector<edge>>g(n);
	int maxv=0;
	rep(i,m){
		int s,t,d;
		cin>>s>>t>>d;
		s--;t--;
		g[s].eb(t,d);
		g[t].eb(s,d);
		chmax(maxv,d);
	}
	int l=0,r=maxv+1;

	auto dfs=[&g](auto self,int w,int v,vector<bool> &ok)->void{
		ok[v]=true;
		for(auto x:g[v]){
			if(!ok[x.to]&&w<=x.cost){
				self(self,w,x.to,ok);
			}
		}
	};
	while(r-l>1){
		int mid=(l+r)/2;
		vector<bool>ok(n);
		dfs(dfs,mid,0,ok);
		if(ok.back()){
			l=mid;
		}else{
			r=mid;
		}
	}
	int w=l;
	vector<int>dis(n,-1);
	dis[0]=0;
	queue<int>q;
	q.emplace(0);
	while(!q.empty()){
		int v=q.front();
		q.pop();
		for(auto x:g[v]){
			if(dis[x.to]==-1&&x.cost>=w){
				dis[x.to]=dis[v]+1;
				q.emplace(x.to);
			}
		}
	}
	int min_dis=dis.back();
	cout<<w<<" "<<min_dis<<"\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}
0