# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
406582 |
2021-05-17T19:02:12 Z |
Falcon |
Robot (JOI21_ho_t4) |
C++17 |
|
3000 ms |
153484 KB |
#include <bits/stdc++.h>
#ifdef DEBUG
#include "debug.hpp"
#endif
using namespace std;
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define traverse(c, it) for(auto it = (c).begin(); it != (c).end(); ++it)
#define rep(i, N) for(int i = 0; i < (N); ++i)
#define rrep(i, N) for(int i = (N) - 1; i >= 0; --i)
#define rep1(i, N) for(int i = 1; i <= (N); ++i)
#define rep2(i, s, e) for(int i = (s); i <= (e); ++i)
#ifdef DEBUG
#define debug(x...) { \
++dbg::depth; \
string dbg_vals = dbg::to_string(x); \
--dbg::depth; \
dbg::fprint(__func__, __LINE__, #x, dbg_vals); \
}
#define light_debug(x) { \
dbg::light = true; \
dbg::dout << __func__ << ":" << __LINE__; \
dbg::dout << " " << #x << " = " << x << endl; \
dbg::light = false; \
}
#else
#define debug(x...) 42
#define light_debug(x) 42
#endif
using ll = long long;
template<typename T>
inline T& ckmin(T& a, T b) { return a = a > b ? b : a; }
template<typename T>
inline T& ckmax(T& a, T b) { return a = a < b ? b : a; }
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, M; cin >> N >> M;
struct edge { int x, c; long long p; };
vector<edge> edges(M);
vector<vector<int>> adj(N);
vector<map<int, long long>> c_sum(N);
rep(i, M) {
edge& e{edges[i]};
int u, v; cin >> u >> v >> e.c >> e.p;
--u, --v, --e.c;
e.x = u ^ v;
c_sum[u][e.c] += e.p;
c_sum[v][e.c] += e.p;
adj[u].push_back(i);
adj[v].push_back(i);
}
priority_queue<tuple<long long, int, int>,
vector<tuple<long long, int, int>>,
greater<tuple<long long, int, int>>> pq;
vector<map<int, long long>> dist(N);
pq.push({0, 0, -1});
auto add = [&](int v, int i, long long d) {
if(dist[v].count(i)) return;
else pq.push({d, v, i});
};
while(!pq.empty()) {
auto [d, u, j] = pq.top(); pq.pop();
if(dist[u].count(j)) continue;
dist[u][j] = d;
for(int i: adj[u]) {
if(i == j) continue;
edge e{edges[i]};
int v{e.x ^ u};
if(j == -1 || edges[j].c != e.c) {
add(v, i, d + e.p);
add(v, -1, d + c_sum[u][e.c] - e.p);
} else {
add(v, i, d + e.p);
add(v, -1, d + c_sum[u][e.c] - e.p - edges[j].p);
}
}
}
debug(dist);
long long ans{-1};
for(auto [_, d]: dist.back()) {
if(ans == -1 || ans > d) ans = d;
}
cout << ans << '\n';
#ifdef DEBUG
dbg::dout << "\nExecution time: "
<< clock() * 1000 / CLOCKS_PER_SEC
<< "ms" << endl;
#endif
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:33:29: warning: statement has no effect [-Wunused-value]
33 | #define debug(x...) 42
| ^~
Main.cpp:101:5: note: in expansion of macro 'debug'
101 | debug(dist);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
10 ms |
716 KB |
Output is correct |
8 |
Correct |
7 ms |
732 KB |
Output is correct |
9 |
Correct |
580 ms |
17208 KB |
Output is correct |
10 |
Correct |
316 ms |
17208 KB |
Output is correct |
11 |
Correct |
852 ms |
66472 KB |
Output is correct |
12 |
Correct |
186 ms |
8904 KB |
Output is correct |
13 |
Correct |
880 ms |
66488 KB |
Output is correct |
14 |
Correct |
869 ms |
66436 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
7 ms |
972 KB |
Output is correct |
17 |
Correct |
5 ms |
844 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
59 ms |
2628 KB |
Output is correct |
20 |
Correct |
3 ms |
716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
616 ms |
33268 KB |
Output is correct |
2 |
Correct |
225 ms |
14404 KB |
Output is correct |
3 |
Execution timed out |
3083 ms |
153484 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
308 KB |
Output is correct |
7 |
Correct |
10 ms |
716 KB |
Output is correct |
8 |
Correct |
7 ms |
732 KB |
Output is correct |
9 |
Correct |
580 ms |
17208 KB |
Output is correct |
10 |
Correct |
316 ms |
17208 KB |
Output is correct |
11 |
Correct |
852 ms |
66472 KB |
Output is correct |
12 |
Correct |
186 ms |
8904 KB |
Output is correct |
13 |
Correct |
880 ms |
66488 KB |
Output is correct |
14 |
Correct |
869 ms |
66436 KB |
Output is correct |
15 |
Correct |
3 ms |
716 KB |
Output is correct |
16 |
Correct |
7 ms |
972 KB |
Output is correct |
17 |
Correct |
5 ms |
844 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
59 ms |
2628 KB |
Output is correct |
20 |
Correct |
3 ms |
716 KB |
Output is correct |
21 |
Correct |
616 ms |
33268 KB |
Output is correct |
22 |
Correct |
225 ms |
14404 KB |
Output is correct |
23 |
Execution timed out |
3083 ms |
153484 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |