QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#47070 | #4382. Path | AsukaKyle# | AC ✓ | 380ms | 22020kb | C++ | 2.2kb | 2022-09-03 16:56:33 | 2022-09-03 16:56:36 |
Judging History
answer
// Author: HolyK
// Created: Sat Sep 3 16:36:50 2022
#include <bits/stdc++.h>
#include <queue>
template <class T, class U>
inline bool smin(T &x, const U &y) {
return y < x ? x = y, 1 : 0;
}
template <class T, class U>
inline bool smax(T &x, const U &y) {
return x < y ? x = y, 1 : 0;
}
using LL = long long;
using PII = std::pair<int, int>;
void solve() {
int n, m, s, k;
std::cin >> n >> m >> s >> k;
s--;
std::set<int> v;
std::vector<int> vis(n), d(n + 1), g(m);
std::vector<std::array<int, 4>> e(m);
int vn = 0;
for (int i = 0; i < m; i++) {
int x, y, w, t;
std::cin >> x >> y >> w >> t;
x--, y--;
e[i] = {x, y, w, t};
d[x]++;
}
for (int i = 1; i <= n; i++) d[i] += d[i - 1];
for (int i = 0; i < m; i++) {
g[--d[e[i][0]]] = i;
}
for (int i = 0; i < n; i++) {
if (i != s) v.insert(i);
}
std::vector<LL> a(n * 2, 1e18);
a[s] = 0;
std::priority_queue<std::pair<LL, int>> q;
q.push({0, s});
std::vector<bool> qv(n * 2);
while (!q.empty()) {
int x = q.top().second;
q.pop();
if (qv[x]) continue;
qv[x] = true;
auto extend = [&](int y, int z) {
if (smin(a[y], a[x] + z)) {
q.push({-a[y], y});
}
};
if (x >= n) {
extend(x - n, 0);
vn++;
for (int i = d[x - n]; i < d[x + 1 - n]; i++) {
vis[e[g[i]][1]] = vn;
}
for (auto it = v.begin(); it != v.end(); ) {
if (vis[*it] == vn) {
it++;
} else {
extend(*it, 0);
it = v.erase(it);
}
}
}
int u, v;
if (x >= n) {
u = x - n;
v = k;
} else {
u = x;
v = 0;
}
for (int i = d[u]; i < d[u + 1]; i++) {
int j = g[i], y = e[j][1], z = e[j][2] - v;
if (e[j][3]) {
extend(y + n, z);
} else {
extend(y, z);
}
}
}
for (int i = 0; i < n; i++) {
if (a[i] == 1e18) a[i] = -1;
std::cout << a[i] << " \n"[i == n - 1];
}
}
int main() {
// freopen("t.in", "r", stdin);
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int t = 1;
std::cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 380ms
memory: 22020kb
input:
13 10 30 2 18468 5 1 37637 0 9 9 45430 0 6 6 41749 0 2 2 21463 1 8 7 50859 0 3 4 18760 0 2 7 38186 0 8 7 33239 0 10 3 44135 0 6 5 47171 0 3 4 36141 0 2 2 46721 0 8 5 51130 0 8 10 27191 0 10 9 30784 0 1 3 18756 0 1 3 37732 0 7 6 34358 0 1 1 33474 0 4 9 38097 0 5 5 37224 0 7 7 32399 0 5 10 43094 0 8 9...
output:
21463 0 21463 21463 21463 45392 38186 21463 21463 21463 41923 0 45987 49920 18690 52316 71251 52316 25059 52316 57062 34860 18647 36256 49111 29152 32554 62744 0 38939 56122 64474 0 -1 84001 29542 39504 -1 -1 38273 46451 44825 44825 44825 57660 38488 44825 44825 44825 0 51281 91636 44602 39997 73418...
result:
ok 13 lines