Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #define ll long long
- #define sqr(x) x * x
- #define pr(x) {x.first, x.second}
- #define forn( i, n) for (int i = 0; i < (int)n; ++i)
- #define all(i) i.begin(), i.end()
- #define rall(i) i.rbegin(), i.rend()
- #include <stdio.h>
- #include <iostream>
- #include <cstdio>
- #include <string>
- #include <vector>
- #include <algorithm>
- #include <cmath>
- #include <fstream>
- #include <queue>
- #include <ctime>
- #include <map>
- #include <set>
- #include <random>
- #include<iomanip>
- #include<future>
- template<typename T>
- inline T abs(const T& a)
- {
- return a < 0 ? -a : a;
- }
- using namespace std;
- void boost()
- {
- #ifdef _DEBUG
- freopen("input.txt", "r", stdin);
- freopen("output.txt", "w", stdout);
- #endif // DEBUG
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- }
- void spr(int x) { cout << setprecision(x) << fixed; }
- long long MOD = 1e9 + 7;
- long double P = 3.141592653589793238462643;
- int INF = 2e9 + 13;
- long long math(int k)
- {
- return 1LL * k * (k + 1) / 2;
- }
- int g[7][7];
- bool used[7];
- int n = 7;
- void BFS(int v)
- {
- used[v] = true;
- cout << v <<" ";
- for (int i = 0; i < n; ++i)
- if (!used[i] && g[v][i] != 0)
- {
- BFS(i);
- used[i] = true;
- }
- }
- int main() {
- boost();
- vector < vector < pair<int, int> > > g(n);
- int m; cin >> m;
- for (int i = 0; i < m; ++i)
- {
- int v, to, l;
- cin >> v >> to >> l;
- g[v].push_back(make_pair(to, l));
- }
- int s = 6;
- vector<int> d(n, INF), p(n);
- d[s] = 0;
- vector<char> u(n);
- for (int i = 0; i < n; ++i) {
- int v = -1;
- for (int j = 0; j < n; ++j)
- if (!u[j] && (v == -1 || d[j] < d[v]))
- v = j;
- if (d[v] == INF)
- break;
- u[v] = true;
- for (size_t j = 0; j < g[v].size(); ++j) {
- int to = g[v][j].first,
- len = g[v][j].second;
- if (d[v] + len < d[to]) {
- d[to] = d[v] + len;
- p[to] = v;
- }
- }
- }
- for (int i = 0; i < n; ++i)
- cout << i << " ---> " << d[i] << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement