# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
385033 |
2021-04-03T02:49:49 Z |
izhang05 |
Robot (JOI21_ho_t4) |
C++17 |
|
314 ms |
23388 KB |
#include <bits/stdc++.h>
using namespace std;
//#define DEBUG
void setIO(string name) {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin.exceptions(istream::failbit);
#ifdef LOCAL
freopen((name + ".in").c_str(), "r", stdin);
freopen((name + ".out").c_str(), "w", stdout);
freopen((name + ".out").c_str(), "w", stderr);
#endif
}
const int maxn = 1e5 + 5;
const long long inf = 1e18;
struct edge {
long long e, c, p;
};
vector<edge> adj[maxn];
long long dist[maxn];
int main() {
setIO("1");
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
int a, b, c, p;
cin >> a >> b >> c >> p;
--a, --b;
adj[a].push_back({b, c, p});
adj[b].push_back({a, c, p});
}
for (int i = 0; i < n; ++i) {
dist[i] = inf;
}
dist[0] = 0;
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<>> q;
q.push({0, 0});
while (!q.empty()) {
map<int, pair<int, long long>> colors;
pair<long long, int> cur = q.top();
q.pop();
long long node = cur.second, cost = cur.first;
if (dist[node] != cost) {
continue;
}
for (auto i : adj[node]) {
++colors[i.c].first;
colors[i.c].second += i.p;
}
for (auto i : adj[node]) {
if (colors[i.c].first == 1) {
if (dist[i.e] > cost) {
#ifdef DEBUG
cout << node << " " << i.e << " " << cost << "\n";
#endif
q.push({dist[i.e] = cost, i.e});
}
} else {
long long nc = cost + min(i.p, colors[i.c].second - i.p);
if (dist[i.e] > nc) {
#ifdef DEBUG
cout << node << " " << i.e << " " << cost << " " << nc << "\n";
#endif
q.push({dist[i.e] = nc, i.e});
}
}
}
}
#ifdef DEBUG
for (int i = 0; i < n; ++i) {
cout << dist[i] << " ";
}
cout << "\n";
#endif
cout << (dist[n - 1] == inf ? -1 : dist[n - 1]) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
3 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
9 |
Incorrect |
4 ms |
2924 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
64 ms |
10604 KB |
Output is correct |
2 |
Correct |
29 ms |
6252 KB |
Output is correct |
3 |
Correct |
91 ms |
16236 KB |
Output is correct |
4 |
Correct |
42 ms |
8044 KB |
Output is correct |
5 |
Incorrect |
314 ms |
23388 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
3 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2668 KB |
Output is correct |
4 |
Correct |
3 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2668 KB |
Output is correct |
6 |
Correct |
2 ms |
2668 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2796 KB |
Output is correct |
9 |
Incorrect |
4 ms |
2924 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |