QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#185325 | #4197. Natural Navigation | rgnerdplayer# | WA | 195ms | 45644kb | C++20 | 2.4kb | 2023-09-21 21:20:12 | 2023-09-21 21:20:13 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
auto solve = [&]() {
int n, m, k;
cin >> n >> m >> k;
vector<int> s(m), t(m), w(m);
vector<vector<int>> c(m), adj(n), radj(n);
for (int i = 0; i < m; i++) {
cin >> s[i] >> t[i] >> w[i];
s[i]--, t[i]--;
adj[s[i]].push_back(i);
radj[t[i]].push_back(i);
int k;
cin >> k;
c[i].resize(k);
for (int j = 0; j < k; j++) {
cin >> c[i][j];
c[i][j]--;
}
}
vector<vector<int>> deg(n);
for (int u = 0; u < n; u++) {
vector<int> cols;
for (auto i : adj[u]) {
cols.insert(cols.end(), c[i].begin(), c[i].end());
}
sort(cols.begin(), cols.end());
cols.erase(unique(cols.begin(), cols.end()), cols.end());
int sz = cols.size();
deg[u].resize(sz);
for (auto i : adj[u]) {
for (auto &x : c[i]) {
x = lower_bound(cols.begin(), cols.end(), x) - cols.begin();
deg[u][x]++;
}
}
}
constexpr i64 INF = 1e18;
priority_queue<pair<i64, int>, vector<pair<i64, int>>, greater<>> h;
vector<i64> dis(n, INF);
h.emplace(0, n - 1);
dis[n - 1] = 0;
auto push = [&](i64 nd, int v) {
if (nd < dis[v]) {
h.emplace(nd, v);
dis[v] = nd;
}
};
while (!h.empty()) {
auto [d, u] = h.top();
h.pop();
if (dis[u] != d) {
continue;
}
for (auto i : radj[u]) {
int v = s[i];
bool ok = false;
for (auto x : c[i]) {
ok |= --deg[v][x] == 0;
}
if (ok) {
push(d + w[i], v);
}
}
}
if (dis[0] == INF) {
cout << "impossible\n";
} else {
cout << dis[0] << '\n';
}
};
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
input:
4 6 2 1 2 6 1 1 1 3 3 1 2 2 3 5 1 2 2 4 8 1 1 3 1 4 2 1 2 3 4 3 1 1
output:
14
result:
ok single line: '14'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3584kb
input:
3 4 3 1 2 300 2 1 2 2 1 2000 2 3 1 1 3 80 2 2 1 2 2 42 1 2
output:
impossible
result:
ok single line: 'impossible'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
3 2 3 1 2 1 3 1 2 3 1 3 1 2 1 2
output:
impossible
result:
ok single line: 'impossible'
Test #4:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
4 5 1 1 4 1 1 1 4 3 1 1 1 3 2 1 1 1 2 1 1 1 1 1 3 1 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #5:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
2 2 3 1 2 3 3 1 2 3 1 2 4 3 1 2 3
output:
4
result:
ok single line: '4'
Test #6:
score: 0
Accepted
time: 0ms
memory: 3552kb
input:
10 12 3 4 4 5 1 1 1 7 5 1 1 1 2 5 1 1 8 4 2 1 1 8 10 5 1 1 6 8 2 1 2 6 5 1 1 2 6 10 7 1 3 5 5 8 1 2 7 1 5 1 1 2 1 6 1 1 2 8 1 1 1
output:
impossible
result:
ok single line: 'impossible'
Test #7:
score: 0
Accepted
time: 0ms
memory: 3620kb
input:
10 19 3 2 2 5 1 2 2 9 4 1 1 2 10 7 1 3 2 4 4 1 3 3 1 9 1 3 5 3 3 1 1 9 3 5 1 2 9 5 10 1 1 9 9 8 1 1 9 6 3 1 3 8 3 6 2 1 3 10 8 8 1 3 10 1 4 1 1 1 9 5 1 1 4 2 2 1 3 4 3 3 1 1 6 9 4 1 2 6 8 4 1 2 6 4 8 1 3
output:
impossible
result:
ok single line: 'impossible'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
10 40 3 4 4 3 2 2 3 4 6 1 1 3 4 10 4 1 2 4 2 4 1 2 4 7 5 2 1 3 6 8 2 2 1 2 6 10 7 1 3 6 2 5 2 2 3 8 10 7 1 3 8 1 10 1 2 9 8 1 1 1 9 10 7 1 1 9 2 10 2 2 3 9 5 9 1 1 10 4 1 1 3 10 6 5 1 1 10 9 10 1 1 10 2 5 1 2 10 1 4 1 2 10 7 9 1 1 2 6 6 1 2 2 8 3 1 3 2 9 8 1 2 2 2 4 2 1 2 2 5 8 1 2 2 7 3 1 1 5 2 1 1...
output:
39
result:
ok single line: '39'
Test #9:
score: 0
Accepted
time: 195ms
memory: 45644kb
input:
10000 498740 1000 7756 7812 146482 1 738 7756 4571 581789 1 497 7756 1367 703256 1 674 7756 8199 491446 1 238 7756 6114 941752 1 26 7756 8739 775363 1 30 7756 2619 313750 1 327 7756 7187 113027 1 268 7756 6943 91064 1 366 7756 4027 565567 1 863 7756 5210 613674 1 45 7756 2625 693644 1 468 7756 5013 ...
output:
172783
result:
ok single line: '172783'
Test #10:
score: 0
Accepted
time: 141ms
memory: 35624kb
input:
1000 393460 1000 423 423 637689 1 427 423 726 460151 1 920 423 311 685370 1 597 423 412 701330 1 553 423 330 717005 1 862 423 676 524095 2 366 411 423 216 69984 1 299 423 272 363386 1 763 423 652 926886 1 928 423 357 607150 1 347 423 927 534335 1 315 423 545 655568 2 267 828 423 842 602690 1 865 423...
output:
33452
result:
ok single line: '33452'
Test #11:
score: 0
Accepted
time: 109ms
memory: 40512kb
input:
2000 484362 2 1289 135 761615 1 2 1289 1163 944919 1 2 1289 507 138396 1 2 1289 1879 154507 1 2 1289 1934 484632 1 2 1289 1049 913244 1 2 1289 626 900547 1 1 1289 1183 718783 1 1 1289 648 250102 1 2 1289 64 202751 1 2 1289 364 916080 1 1 1289 1970 703438 1 2 1289 382 559816 1 1 1289 1232 544698 1 2 ...
output:
impossible
result:
ok single line: 'impossible'
Test #12:
score: 0
Accepted
time: 100ms
memory: 35528kb
input:
1000 421412 3 296 81 449614 1 3 296 636 731202 1 3 296 149 645560 1 2 296 560 570799 1 2 296 92 483079 1 3 296 83 65086 1 2 296 239 502528 1 3 296 692 952771 1 1 296 387 27706 1 3 296 489 203962 1 1 296 583 276352 1 3 296 968 443564 2 1 3 296 68 859602 1 2 296 432 245638 1 2 296 294 933292 1 3 296 2...
output:
impossible
result:
ok single line: 'impossible'
Test #13:
score: 0
Accepted
time: 104ms
memory: 35028kb
input:
1000 413799 4 570 396 203345 1 3 570 801 3447 2 2 4 570 393 825231 1 2 570 161 433365 1 4 570 44 855873 1 1 570 127 873092 1 1 570 781 749825 1 3 570 897 334612 1 1 570 953 166340 1 3 570 922 865765 3 1 2 3 570 259 949726 1 2 570 932 770327 1 1 570 640 140986 2 1 4 570 871 92089 1 2 570 326 262958 1...
output:
impossible
result:
ok single line: 'impossible'
Test #14:
score: -100
Wrong Answer
time: 130ms
memory: 26400kb
input:
25000 250000 6 17414 524 2552 2 1 5 6925 13350 4266 2 1 5 21567 1185 10194 2 5 6 6852 11401 5660 2 1 2 4925 10674 1 2 3 6 17895 7429 1 2 4 5 10990 5624 1 2 5 6 17763 9586 4510 2 2 4 3807 23200 1 2 3 6 16899 3423 17559 2 2 3 65 20870 9386 2 1 5 19750 16854 9277 2 2 3 5144 12747 1473 2 2 6 10320 1974 ...
output:
24999
result:
wrong answer 1st lines differ - expected: '25003', found: '24999'