-
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#include<iostream>#include<vector>#include<queue>#include<utility>using namespace std;class PAIR {public:int x, y;PAIR(int x, int y) {this->x = x;this->y = y;}};int tc,n, d, c;vector<PAIR> map[20000];int visit[20000];//bool dist[20000];int node, edge;int INF = 987654321;int dist[20000];void dijkstra(int start) {visit[start] = 0;priority_queue<pair<int, int> > pq;pq.pop();//if (visit[current] < distance) continue;for(int i = 0; i< map[current].size(); i++){int next = visit[current] + map[current][i].y;int before = visit[map[current][i].x];if (next < before) {visit[map[current][i].x] = next;}}}}int main() {ios_base::sync_with_stdio(0);cin.tie(0);cin >> node >> edge;for (int i = 0; i < node; i++) {visit[i] = INF;}for (int i = 0; i < edge; i++) {int a, b, c;cin >> a >> b >> c;map[a - 1].push_back(PAIR(b-1,c));//map[b - 1].push_back({ a - 1,c });}int start, ending;cin >> start >> ending;dijkstra(start-1);cout << visit[ending - 1]<<'\n';/*for (int i = 0; i < node; i++) {if (visit[i] != INF)cout << visit[i] << '\n';elsecout << "INF" << '\n';}*/return 0;}http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
똑같은 다익스트라 문제