This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/// Template path: /home/mohammed/.config/sublime-text-3/Packages/User
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
// typedef
typedef long long ll;
typedef long double ld;
typedef vector<int> vecint;
typedef vector<char> vecchar;
typedef vector<string> vecstr;
typedef vector<long long> vecll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// Marcos
#define endl ("\n")
#define int long long
#define mod 1000000007
#define pi (3.141592653589)
#define REP(i,a,b) for (int i = a; i < b; i++)
#define RREP(i,a,b) for (int i = a; i > b; i--)
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
// Functions
long long squared(long long x) {return (x * x) % mod;}
int factorial(int n) {long long res = 1; for (int i = 1; i <= n; i++) {res = ((res * i) % mod + mod) % mod ;} return res;}
long long power(long long x, long long p) {if (p == 0) {return 1;} if (p % 2 == 1) {return (power(x, p - 1) * x) % mod;} return squared(power(x, p / 2));}
// cout << fixed;
// cout << setprecision(4);
// ---------(^_^)--------- //
void main_solve() {
int n, e, k; cin >> n >> e >> k;
cin >> k;
vector<vector<vector<int>>> edg(n);
for (int i = 0; i < e; i ++) {
int a, b, c; cin >> a >> b >> c;
edg[b].push_back({a, c});
}
vector<int> cost(n, LLONG_MAX);
vector<int> vis(n);
priority_queue<pair<int, int>> q;
cost[k] = 0;
q.push({0, k});
while (!q.empty()) {
int a = q.top().second; q.pop();
if (vis[a]) continue;
vis[a]++;
for (auto &i : edg[a]) {
int b = i[0], w = i[1];
if (cost[a] + w < cost[b]) {
cost[b] = cost[a] + w;
q.push({ -cost[b], b});
}
}
}
int t; cin >> t;
while (t--) {
int s, p1, p2, p3, p4, p5;
cin >> s >> p1 >> p2 >> p3 >> p4 >> p5;
if (cost[s] == LLONG_MAX) {
cout << -1 << endl;
} else {
cout << cost[s] << endl;
}
}
}
int32_t main() {
fast;
// #ifndef ONLINE_JUDGE
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
// #endif
// Just another problem (-_-)
int t;
t = 1;
// cin >> t;
while (t--) {
main_solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |