제출 #714113

#제출 시각아이디문제언어결과실행 시간메모리
714113william950615Commuter Pass (JOI18_commuter_pass)C++14
16 / 100
485 ms32600 KiB
#include<bits/stdc++.h> using namespace std; #define F first #define S second #define mkp make_pair #define MEM(x) memset(x, 0, sizeof(x)) #define SZ(x) int(x.size()) #define ALL(x) begin(x), end(x) #define REP(i,n) for( int i = 0; i < n; ++i ) #define FOR(i,a,b) for( int i = (a); i <= b; ++i ) #define RFOR(i,a,b) for( int i = (a); i >= b; --i ) #define EB emplace_back #define EP emplace #ifdef DEBUG template<typename T> void _DO(T&&x){cerr << x << '\n'} template<typename A, typename ...B> void _OD(A&&a, B&&...b){cerr << a <<','; _DO(b...);}; #define de(...) do{\ fprintf(stderr, "%s-%d (%s):", __func__, __LINE__, #__VA_ARGS__);\ _DO(__VA_ARGS__);\ }while(0); #else #define de(...) #endif typedef long long ll; typedef pair<int,int> pii; typedef array<ll, 2> arr; template<typename T> using V = vector<T>; constexpr int mxN = 3e5+1; constexpr ll inf = 1e18; vector<arr> graph[ mxN ]; struct ShortPath { int st; ll dis[ mxN ]; void DO() { priority_queue< arr, V<arr>, greater<arr>> pq; pq .EP( arr{0, st} ); while( !pq.empty() ) { auto a = pq.top(); pq.pop(); if( dis[ a[1] ] != inf ) continue; dis[ a[1] ] = a[0]; for( auto &i : graph[ a[1] ] ) { if( dis[ i[1] ] != inf ) continue; pq.EP( arr{ a[0]+i[0], i[1] }); } } }; ll operator() (int t ) { return dis[ t ] ; }; ShortPath( int _st ) { st = _st; for( auto &i : dis ) i = inf; DO(); }; }; inline void solve() { int N, M; cin >> N >> M; int s, t; cin >> s >> t; int u, v; cin >> u >> v; REP(edge, M ){ int a, b, c; cin >> a >> b >> c; graph[ a ].EB( arr{c,b} ); graph[ b ].EB( arr{c,a} ); } ShortPath froms(s), fromv(v), fromt(t); ll ans = inf; /* for( int i = 1; i <= N; ++i ) { cout << froms(i) << ' '; } cout << '\n'; for( int i = 1; i <= N; ++i ) { cout << fromt(i) << ' '; } cout << '\n'; */ for( int i = 1; i <= N; ++i ) { if( froms(i) + fromt(i) == froms(t) ) ans = min( fromv(i), ans ); } cout << ans << '\n'; } int main () { int T = 1; #ifdef Local cin >> T; #endif while(T--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...