結果

問題 No.1473 おでぶなおばけさん
ユーザー むかでむかで
提出日時 2021-04-09 21:54:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 2,866 bytes
コンパイル時間 2,127 ms
コンパイル使用メモリ 210,516 KB
実行使用メモリ 9,380 KB
最終ジャッジ日時 2023-09-07 11:00:44
合計ジャッジ時間 7,361 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 94 ms
9,260 KB
testcase_03 AC 71 ms
8,404 KB
testcase_04 AC 66 ms
6,412 KB
testcase_05 AC 28 ms
4,384 KB
testcase_06 AC 113 ms
8,520 KB
testcase_07 AC 96 ms
9,372 KB
testcase_08 AC 135 ms
9,372 KB
testcase_09 AC 84 ms
9,380 KB
testcase_10 AC 39 ms
5,352 KB
testcase_11 AC 49 ms
6,264 KB
testcase_12 AC 39 ms
5,700 KB
testcase_13 AC 23 ms
4,760 KB
testcase_14 AC 18 ms
4,376 KB
testcase_15 AC 40 ms
5,544 KB
testcase_16 AC 34 ms
4,880 KB
testcase_17 AC 4 ms
4,380 KB
testcase_18 AC 7 ms
4,380 KB
testcase_19 AC 44 ms
5,624 KB
testcase_20 AC 56 ms
7,812 KB
testcase_21 AC 66 ms
6,984 KB
testcase_22 AC 46 ms
8,392 KB
testcase_23 AC 38 ms
7,884 KB
testcase_24 AC 38 ms
7,564 KB
testcase_25 AC 144 ms
8,304 KB
testcase_26 AC 145 ms
8,256 KB
testcase_27 AC 35 ms
4,724 KB
testcase_28 AC 109 ms
9,324 KB
testcase_29 AC 66 ms
6,944 KB
testcase_30 AC 88 ms
7,756 KB
testcase_31 AC 74 ms
9,284 KB
testcase_32 AC 76 ms
8,820 KB
testcase_33 AC 59 ms
7,692 KB
testcase_34 AC 34 ms
5,400 KB
testcase_35 AC 33 ms
5,404 KB
testcase_36 AC 53 ms
6,144 KB
testcase_37 AC 80 ms
7,584 KB
testcase_38 AC 12 ms
4,376 KB
testcase_39 AC 37 ms
4,932 KB
testcase_40 AC 34 ms
5,132 KB
testcase_41 AC 30 ms
4,908 KB
testcase_42 AC 31 ms
4,956 KB
testcase_43 AC 37 ms
6,980 KB
testcase_44 AC 38 ms
6,948 KB
testcase_45 AC 39 ms
6,880 KB
testcase_46 AC 58 ms
7,240 KB
testcase_47 AC 73 ms
8,248 KB
testcase_48 AC 69 ms
7,852 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define ins insert

#define debug(a) cerr<<(a)<<endl
#define dbrep(a,n) rep(_i,n) cerr<<(a[_i])<<" "; cerr<<endl
#define dbrep2(a,n,m) rep(_i,n){rep(_j,m) cerr<<(a[_i][_j])<<" "; cerr<<endl;}

using namespace std;

template<class A, class B>
ostream &operator<<(ostream &os, const pair<A,B> &p){return os<<"("<<p.fi<<","<<p.se<<")";}
template<class A, class B>
istream &operator>>(istream &is, pair<A,B> &p){return is>>p.fi>>p.se;}

/* Some Libraries */

//-------------------------------------------------

//-------------------------------------------------
//--Graph Template
//-------------------------------------------------
template<class E>
struct Graph
{
    vector<vector<E> > adj;
    Graph(int N):adj(N){}
    virtual void add_edge(int v, E e){adj[v].push_back(e);}
    vector<E>& operator[](int v){return adj[v];}
    inline int size(){return adj.size();}
};

struct NormalEdge {
    int to;
    NormalEdge(int to):to(to){}
};

struct UWGraph : public Graph<NormalEdge>
{
    UWGraph(int N):Graph(N){}
    void add_edge(int v, int e){adj[v].push_back({e});}
};

//-------------------------------------------------
//--Dist BFS
//-------------------------------------------------
template<class E>
vector<int> distBFS(Graph<E> &G, int s, int weight)
{
    vector<int> dist(G.size(),-1); dist[s]=0;
    queue<int> que; que.push(s);
    while(!que.empty()){
        int v = que.front(); que.pop();
        for(auto e:G[v]){
            if (dist[e.to]!=-1) continue;
			if (weight > e.w) continue;
            dist[e.to]=dist[v]+1;
            que.push(e.to);
        }
    }
    return dist;
}

struct Edge {
	int to,w;
};

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	int N,M; cin>>N>>M;

	Graph<Edge> G(N);
	rep(i,M){
		int a,b,d; cin>>a>>b>>d; a--; b--;
		G.add_edge(a,{b,d});
		G.add_edge(b,{a,d});
	}
	int ans=-1;
	int lo=0, hi=1e9+1;
	while(hi-lo>1){
		int mid = (lo+hi)/2;
		auto dist = distBFS(G,0,mid);
		if (dist[N-1]==-1){
			hi=mid;
		}else{
			lo=mid;
			ans = dist[N-1];
		}
	}
	cout<<lo<<" "<<ans<<"\n";
    return 0;
}
0