# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
945196 |
2024-03-13T14:03:11 Z |
May27_th |
Robot (JOI21_ho_t4) |
C++17 |
|
3000 ms |
83084 KB |
#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
void World_Final();
void Solve();
int main(){
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(taskname".in", "r")) {
freopen(taskname".in", "r", stdin);
freopen(taskname".out", "w", stdout);
}
World_Final();
}
void World_Final(){
int Tests = 1;
//cin >> Tests;
for (int i = 1; i <= Tests; i ++) {
//cout << i << "\n";
Solve();
}
}
const int MAXN = 1e5 + 10;
const int64_t INF = 1e18;
int N, M;
struct Edge{ int to, c, p; };
vector<Edge> G[MAXN]; map<int, int64_t> sum[MAXN], f[MAXN]; map<int, pair<int64_t, int64_t>> cost[MAXN];
void Solve(){
cin >> N >> M; for (int i = 1; i <= M; i ++) {
int u, v, c, p; cin >> u >> v >> c >> p;
G[u].push_back({v, c, p});
G[v].push_back({u, c, p});
sum[u][c] += p;
sum[v][c] += p;
} f[1][0] = 0; cost[1][0] = make_pair(0, 0);
priority_queue<pair<int64_t, pair<int, int>>> pq; pq.push(make_pair(0, make_pair(1, 0)));
while (!pq.empty()) {
int d = pq.top().first;
int u, prevc; tie(u, prevc) = pq.top().second; pq.pop();
if (-d != f[u][prevc]) continue;
for (auto [v, c, p] : G[u]) {
/// Change color of current edge
if (f[v].find(0) == f[v].end() || f[v][0] > f[u][prevc] + p) {
f[v][0] = f[u][prevc] + p;
cost[v][0] = make_pair(c, p);
pq.push(make_pair(-f[v][0], make_pair(v, 0)));
}
/// Change color of other edges
int64_t add = sum[u][c] - p + (cost[u][prevc].first == c ? cost[u][prevc].second : 0);
if (f[v].find(c) == f[v].end() || f[v][c] > f[u][prevc] + add) {
f[v][c] = f[u][prevc] + add;
cost[v][c] = make_pair(c, add);
pq.push(make_pair(-f[v][c], make_pair(v, c)));
}
}
}
int64_t ans = INF;
for (auto [c, v] : f[N]) {
ans = min(ans, v);
//cout << c << " " << v << "\n";
}
cout << (ans == INF ? -1 : ans);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:11:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
11 | freopen(taskname".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:12:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | freopen(taskname".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16884 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16892 KB |
Output is correct |
4 |
Correct |
4 ms |
16732 KB |
Output is correct |
5 |
Correct |
5 ms |
16732 KB |
Output is correct |
6 |
Correct |
5 ms |
16732 KB |
Output is correct |
7 |
Correct |
6 ms |
16864 KB |
Output is correct |
8 |
Correct |
4 ms |
16732 KB |
Output is correct |
9 |
Incorrect |
101 ms |
17536 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
165 ms |
38076 KB |
Output is correct |
2 |
Correct |
69 ms |
28108 KB |
Output is correct |
3 |
Correct |
142 ms |
34512 KB |
Output is correct |
4 |
Correct |
90 ms |
31824 KB |
Output is correct |
5 |
Execution timed out |
3035 ms |
83084 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
16884 KB |
Output is correct |
2 |
Correct |
4 ms |
16732 KB |
Output is correct |
3 |
Correct |
4 ms |
16892 KB |
Output is correct |
4 |
Correct |
4 ms |
16732 KB |
Output is correct |
5 |
Correct |
5 ms |
16732 KB |
Output is correct |
6 |
Correct |
5 ms |
16732 KB |
Output is correct |
7 |
Correct |
6 ms |
16864 KB |
Output is correct |
8 |
Correct |
4 ms |
16732 KB |
Output is correct |
9 |
Incorrect |
101 ms |
17536 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |