# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
699179 | Markomafko972 | Robot (JOI21_ho_t4) | C++14 | 76 ms | 14172 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 X first
#define Y second
#define pb push_back
#define pii pair<int, int>
typedef long long ll;
using namespace std;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const int OFF = (1 << 20);
int n, m, a, b, c, d;
vector< pair<int, pii> > v[100005];
ll dist[100005];
set< pair<ll, int> > s;
set<int> boja[100005];
int kol[200005];
void dijkstra() {
while (!s.empty()) {
ll cost = s.begin() -> first;
int cvor = s.begin() -> second;
s.erase(s.begin());
for (int i = 0; i < v[cvor].size(); i++) kol[v[cvor][i].Y.X]++;
while (!boja[cvor].empty()) {
kol[*(boja[cvor].begin())]--;
boja[cvor].erase(boja[cvor].begin());
}
for (int i = 0; i < v[cvor].size(); i++) {
int sus = v[cvor][i].X;
int cijena = v[cvor][i].Y.Y;
if (kol[v[cvor][i].Y.X] == 1) cijena = 0;
if (cost+cijena < dist[sus]) {
s.erase({dist[sus], sus});
dist[sus] = cost+cijena;
s.insert({dist[sus], sus});
boja[sus].clear();
boja[sus].insert(v[cvor][i].Y.X);
}
else if (cost+cijena == dist[sus]) {
boja[sus].insert(v[cvor][i].Y.X);
}
}
for (int i = 0; i < v[cvor].size(); i++) kol[v[cvor][i].Y.X] = 0;
}
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m;
for (int i = 0; i < m; i++) {
cin >> a >> b >> c >> d;
v[a].push_back({b, {c, d}});
v[b].push_back({a, {c, d}});
}
s.insert({0, 1});
for (int i = 2; i <= n; i++) {
dist[i] = INF;
s.insert({INF, i});
}
dijkstra();
if (dist[n] == INF) cout << -1;
else cout << dist[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... |