Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #include <iostream>
- #include <string>
- #include <map>
- #include <set>
- #include <algorithm>
- #include <vector>
- #include <stdio.h>
- #include <cmath>
- #include <math.h>
- #include <queue>
- #include <stack>
- #include <climits>
- #include <deque>
- #include <ctime>
- using namespace std;
- typedef long long ll;
- typedef unsigned long long llu;
- #define modulo pow(10,9)+7
- #define eps pow(10,-9)
- #define forn(i, n) for(int i = 0; i < n; ++i)
- #define rforn(i, n) for (int i = n; i >= 0; --i)
- #define files freopen("input.txt", "rt", stdin); freopen("output.txt", "wt", stdout)
- #define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
- #define all(n) n.begin(), n.end()
- #define rall(n) n.rbegin(), n.rend()
- vector<pair<int, int>> graf[501];
- int S[501];
- void decs(int a)
- {
- queue<int>next;
- next.push(a);
- S[a] = 0;
- while (next.size() != 0)
- {
- int now = next.front();
- next.pop();
- for (int i = 0; i < graf[now].size(); i++)
- {
- if (S[graf[now][i].first] < S[now] + graf[now][i].second)
- {
- S[graf[now][i].first] = S[now] + graf[now][i].second;
- next.push(graf[now][i].first);
- }
- }
- }
- }
- int main()
- {
- int n, m, a, b;
- int prom, prom2, l;
- cin >> n >> m;
- for (int i = 1; i <= 500; i++)
- {
- S[i] = 0;
- }
- for (int i = 1; i <= m; i++)
- {
- cin >> prom >> prom2 >> l;
- graf[prom].push_back({ prom2,l });
- }
- cin >> a >> b;
- if (graf[a].size() != 0)
- {
- decs(a);
- if (S[b] == 0 && b != a)
- {
- cout << "No solution";
- }
- else
- cout << S[b];
- }
- else
- cout << "No solution";
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment