제출 #601494

#제출 시각아이디문제언어결과실행 시간메모리
601494narvalo페리들 (NOI13_ferries)C++17
0 / 40
279 ms28500 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int INF = (int)1e18; int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int n , m; cin >> n >> m; vector<vector<pair<int , int>>> adj(n) , rev(n); vector<vector<int>> edges(n); for (int i = 0 ; i < m ; i += 1) { int a , b , c; cin >> a >> b >> c; a -= 1 , b -= 1; edges[a].push_back(c); adj[a].emplace_back(b , c); rev[b].emplace_back(a , c); } for (int i = 0 ; i < n ; i += 1) { sort(edges[i].begin() , edges[i].end()); } #define pi pair<int , int> priority_queue<pi , vector<pi> , greater<pi>> pq; vector<int> d(n , INF); d[n - 1] = 0; pq.emplace(d[n - 1] , n - 1); while (!pq.empty()) { auto t = pq.top(); pq.pop(); if (d[t.second] != t.first) continue; for (int i = 0 ; i < (int)rev[t.second].size() ; i += 1) { auto node = rev[t.second][i]; if (d[node.first] > t.first + edges[node.first].back()) { d[node.first] = t.first + edges[node.first].back(); pq.emplace(d[node.first] , node.first); edges[node.first].pop_back(); } } } cout << d[0] << '\n'; 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...