# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1037758 | tradz | Robot (JOI21_ho_t4) | C++14 | 41 ms | 30516 KiB |
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 <bits/stdc++.h>
#define For(i,a,b) for(int i = a; i <= b; i++)
#define Ford(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define ii pair<ll,int>
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define RRH(v) v.resize(unique(all(v)) - v.begin())
using namespace std;
const int N = 1e6+7;
const int M = 1e9+7;
const ll oo = 3e18;
int n, m;
ll d[N];
struct data {
int v, c, p;
};
vector<data> g[N];
void dij() {
For (i, 2, n) d[i] = oo;
d[1] = 0;
priority_queue<ii, vector<ii>, greater<ii>> q;
q.push({0ll, 1});
while (q.size() > 0) {
ii k = q.top();
q.pop();
if (d[k.se] != k.fi) continue;
unordered_map<int,ll> ma;
for (auto x: g[k.se]) {
ma[x.c] += x.p;
}
for (auto x: g[k.se]) {
if (d[x.v] > k.fi + x.p) {
d[x.v] = k.fi + x.p;
q.push({d[x.v], x.v});
}
if (d[x.v] > k.fi + ma[x.c] - x.p) {
d[x.v] = d[k.fi] + x.p;
q.push({d[x.v], x.v});
}
}
}
if (d[n] >= oo) d[n] = -1;
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
#define TASK ""
if (fopen (".inp", "r")) {
freopen (".inp", "r", stdin);
freopen (".out", "w", stdout);
}
if(fopen(TASK".inp", "r")) {
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
cin >> n >> m;
For (i, 1, m) {
int u, v, c, p; cin >> u >> v >> c >> p;
g[u].push_back({v, c, p});
g[v].push_back({u, c, p});
}
dij();
cout << d[n] << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |