Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define PSB push_back
- #define ll long long
- #define MP make_pair
- #define FastIO ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
- constexpr ll mod = 1e9 + 7;
- const ll N=3e6+5;
- int n,m;
- const int INF = 1000000000;
- vector<vector<pair<int, int>>> adj;
- //vector<int> d(N),p(N);
- void dijkstra(int s, vector<int> & d, vector<int> & p) {
- int n = adj.size();
- d.assign(n, INF);
- p.assign(n, -1);
- d[s] = 0;
- using pii = pair<int, int>;
- priority_queue<pii, vector<pii>, greater<pii>> q;
- q.push({0, s});
- while (!q.empty()) {
- int v = q.top().second;
- int d_v = q.top().first;
- q.pop();
- if (d_v != d[v])
- continue;
- for (auto edge : adj[v]) {
- int to = edge.first;
- int len = edge.second;
- if (d[v] + len < d[to]) {
- d[to] = d[v] + len;
- p[to] = v;
- q.push({d[to], to});
- }
- }
- }
- }
- int main(){
- FastIO
- //int n,m;
- cin>>n>>m;
- for(int i=0;i<m;i++){
- int a,b,w; cin>>a>>b>>w;
- --a,--b;
- adj[a].PSB(MP(b,w));
- adj[b].PSB(MP(a,w));
- }
- //dijkstra(1, d, p);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment