This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "crocodile.h"
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(x, a, b) for(int x=a;x < int(b); x++)
#define endl '\n'
#define TESTCASE ll t; cin >> t; for(ll T=0; T < t; T++)
using namespace std;
// using namespace __gnu_pbds;
// typedef tree<int,null_type,less<int>, rb_tree_tag, tree_order_statistics_node_update> Indexed_set;
typedef long long int ll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vpi;
typedef long double ld;
const int INF = 1e9;
const ll INIT = 7;
const ll MAX_VAL = (ll) 1e9;
const ll MAX_SZ = (ll) 2e5;
const long double eps = 1e-4;
const int MOD = 998244353;
vi rd = {0, 1 , 0, -1}, cd = {1, 0, -1, 0};
const int MAX_DIST = int(1e9);
int travel_plan(int n, int m, int r[][2], int* l, int k, int* p) {
vector<vpi> adj(n);
FOR(i, 0, m) {
int f = r[i][0], s = r[i][1];
adj[f].push_back(make_pair(l[i], s));
adj[s].push_back(make_pair(l[i], f));
}
vi ans(n, -2);
priority_queue<pi, vpi, greater<pi>> tr;
FOR(i, 0, k) {
tr.push(make_pair(0, p[i]));
ans[p[i]] = -1;
}
while(!tr.empty()) {
auto [dist, chamber] = tr.top();
tr.pop();
if(ans[chamber] == -2) {
ans[chamber]++;
continue;
}
if(ans[chamber] >= 0 || dist > MAX_DIST) continue;
ans[chamber] = dist;
for(auto next : adj[chamber]) {
tr.push(make_pair(dist + next.first, next.second));
}
}
// FOR(i, 0, n) cout << ans[i] << " ";
// cout << endl;
return ans[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |