제출 #459176

#제출 시각아이디문제언어결과실행 시간메모리
459176TeaTimeCommuter Pass (JOI18_commuter_pass)C++17
31 / 100
1171 ms25856 KiB
//#pragma GCC optimize("O3") //#pragma GCC target("avx2") #include <iostream> #include <vector> #include <string> #include <algorithm> #include <map> #include <set> #include <queue> #include <unordered_map> using namespace std; #define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); typedef long long ll; typedef long double ld; const ll SZ = 1e5 + 100, INF = 1e9 * 1e9 + 100; vector<vector<pair<ll, ll>>> gr; ll n, m, s, t, u, v; ll dist[SZ][2], d[SZ]; void djikstra(int v, int ind) { set<pair<ll, ll>> st; for (int i = 0; i < n; i++) { dist[i][ind] = INF; } dist[v][ind] = 0; for (int i = 0; i < n; i++) st.insert({ dist[i][ind], i }); while (!st.empty()) { pair<ll, ll> v = (*st.begin()); st.erase(st.begin()); for (auto to : gr[v.second]) { if (dist[to.first][ind] > v.first + to.second) { st.erase({ dist[to.first][ind], to.first }); dist[to.first][ind] = v.first + to.second; st.insert({ dist[to.first][ind], to.first }); } } } } ll find_ans(int u, int v) { set<pair<ll, ll>> st; for (int i = 0; i < n; i++) { d[i] = INF; } d[v] = 0; for (int i = 0; i < n; i++) st.insert({ d[i], i }); while (!st.empty()) { pair<ll, ll> v = (*st.begin()); st.erase(st.begin()); for (auto to : gr[v.second]) { if (d[to.first] > v.first + to.second) { st.erase({ d[to.first], to.first }); d[to.first] = v.first + to.second; st.insert({ d[to.first], to.first }); } int s2 = v.second, t2 = to.first; if (dist[s2][0] + dist[t2][1] + to.second == dist[t][0]) { if (d[to.first] > v.first) { st.erase({ d[to.first], to.first }); d[to.first] = v.first; st.insert({ d[to.first], to.first }); } } } } return d[u]; } int main() { fastInp; cin >> n >> m; cin >> s >> t; cin >> u >> v; s--; t--; u--; v--; gr.resize(n); for (int i = 0; i < m; i++) { ll u, v, c; cin >> u >> v >> c; u--; v--; gr[u].push_back({ v, c }); gr[v].push_back({ u, c }); } djikstra(s, 0); djikstra(t, 1); ll a = find_ans(u, v); ll b = find_ans(v, u); cout << min(a, b); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...