# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
331578 |
2020-11-29T03:08:33 Z |
syy |
Olympic Bus (JOI20_ho_t4) |
C++17 |
|
83 ms |
6764 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define FOR(i, a, b) for(ll i = (ll)a; i <= (ll)b; i++)
#define DEC(i, a, b) for(ll i = (ll)a; i >= (ll)b; i--)
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<ll, pi> ipi;
typedef pair<pi, pi> pipi;
#define f first
#define s second
typedef vector<ll> vi;
typedef vector<pi> vpi;
typedef vector<pii> vpii;
#define pb push_back
#define pf push_front
#define all(v) v.begin(), v.end()
#define size(v) (ll) v.size()
#define disc(v) sort(all(v)); v.resize(unique(all(v)) - v.begin());
#define INF (ll) 1e9 + 100
#define LLINF (ll) 1e15
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sandybridge __attribute__((optimize("Ofast"), target("arch=sandybridge")))
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //can be used by calling rng() or shuffle(A, A+n, rng)
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
ll n, m, a, b, c, d, dist[2][205], ndist[2][205], ans, path[2][205];
pipi edge[50005];
vpii adj[205], radj[205];
priority_queue<pi, vpi, greater<pi>> pq;
void setpath() {
FOR(i, 1, n) dist[0][i] = LLINF;
dist[0][1] = 0;
pq.push(pi(0, 1));
while (!pq.empty()) {
auto [d, x] = pq.top(); pq.pop();
if (d > dist[0][x]) continue;
for (auto [t, idx]:adj[x]) {
auto [it, nd] = t;
if (dist[0][it] > d + nd) {
dist[0][it] = d + nd;
path[0][it] = idx;
pq.push(pi(d + nd, it));
}
}
}
FOR(i, 1, n) dist[1][i] = LLINF;
dist[1][n] = 0;
pq.push(pi(0, n));
while (!pq.empty()) {
auto [d, x] = pq.top(); pq.pop();
if (d > dist[1][x]) continue;
for (auto [t, idx]:adj[x]) {
auto [it, nd] = t;
if (dist[1][it] > d + nd) {
dist[1][it] = d + nd;
path[1][it] = idx;
pq.push(pi(d + nd, it));
}
}
}
}
void dijkstra(bool b, ll flip) {
FOR(i, 1, n) ndist[b][i] = LLINF;
dist[b][(b ? n : 1)] = 0;
pq.push(pi(0, (b ? n : 1)));
while (!pq.empty()) {
auto [d, x] = pq.top(); pq.pop();
if (d > ndist[b][x]) continue;
for (auto [t, idx]:adj[x]) {
auto [it, nd] = t;
if (idx == flip) continue;
if (ndist[b][it] > d + nd) {
ndist[b][it] = d + nd;
pq.push(pi(d + nd, it));
}
}
if (x == edge[flip].f.s) {
ll it = edge[flip].f.f, nd = edge[flip].s.f;
if (ndist[b][it] > d + nd) {
ndist[b][it] = d + nd;
pq.push(pi(d + nd, it));
}
}
}
}
int main() {
fastio; cin >> n >> m;
FOR(i, 1, m) {
cin >> a >> b >> c >> d;
adj[a].pb(pii(pi(b, c), i));
radj[b].pb(pii(pi(a, c), i));
edge[i] = pipi(pi(a, b), pi(c, d));
}
setpath();
ans = dist[0][n] + dist[1][1];
FOR(i, 1, m) {
auto [t, tt] = edge[i];
auto [a, b] = t;
auto [c, d] = tt;
ll res = d;
if (path[0][b] == i) {
dijkstra(0, i);
res += ndist[0][n];
} else res += min(dist[0][n], dist[0][b] + c + dist[1][a]);
if (path[1][b] == i) {
dijkstra(1, i);
res += ndist[1][1];
} else res += min(dist[1][1], dist[1][b] + c + dist[0][a]);
ans = min(ans, res);
}
cout << (ans >= LLINF ? -1 : ans);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
11 ms |
492 KB |
Output is correct |
4 |
Correct |
12 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Incorrect |
16 ms |
492 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
6764 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
54 ms |
4972 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
56 ms |
6732 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Incorrect |
29 ms |
6636 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
11 ms |
492 KB |
Output is correct |
4 |
Correct |
12 ms |
492 KB |
Output is correct |
5 |
Correct |
2 ms |
492 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
492 KB |
Output is correct |
10 |
Incorrect |
16 ms |
492 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |