QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#817574 | #9821. Kruidnoten | nitram# | WA | 350ms | 23720kb | C++14 | 1.6kb | 2024-12-17 05:57:02 | 2024-12-17 05:57:02 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define inf LLONG_MAX / 2
using namespace std;
vector<ll> dijk(int N, vector<vector<pair<int, int>>> &adj, int s) {
vector<ll> cost(N, inf);
priority_queue<pair<ll, int>> q;
q.push({0, s});
while (!q.empty()) {
auto t = q.top();
q.pop();
if (cost[t.second] != inf) continue;
cost[t.second] = -t.first;
for (pair<int, int> e: adj[t.second]) {
q.push({t.first - e.second, e.first});
}
}
return cost;
}
int main() {
int N, M, K;
cin >> N >> M >> K;
vector<vector<pair<int, int>>> adj(N);
for (int i = 0; i < M; i++)
{
int u, v, w;
cin >> u >> v >> w;
u--; v--;
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
vector<double> p(N);
while (K--) {
int i;
double d;
cin >> i >> d;
p[i - 1] = d;
}
vector<ll> ch = dijk(N, adj, 0);
vector<ll> cu = dijk(N, adj, N - 1);
vector<ll> c(N);
for (int i = 0; i < N; i++)
{
c[i] = min(inf, ch[i] + cu[i]);
}
for (int i = 0; i < N; i++)
{
if (p[i] == 1 && c[i] != inf) goto yes;
}
cout << "impossible" << endl;
return 0;
yes:
vector<pair<ll, double>> paths;
for (int i = 0; i < N; i++)
{
paths.push_back({c[i], p[i]});
}
sort(paths.begin(), paths.end());
double r = 1;
double e = 0;
for (auto i: paths) {
e += r * i.second * i.first;
r *= 1 - i.second;
}
cout << e << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4032kb
input:
5 5 3 1 2 6 3 1 4 4 5 2 1 4 1 3 4 5 2 1.0 3 0.4 5 0.1
output:
12.36
result:
ok
Test #2:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
6 5 2 1 2 1 1 3 1 4 5 3 5 6 1 6 3 2 1 0.6283 4 0.3142
output:
impossible
result:
ok
Test #3:
score: 0
Accepted
time: 350ms
memory: 21868kb
input:
100000 200000 100000 44294 64249 1692 7378 18852 7776 39463 38431 606 20000 70894 1855 62415 45345 9503 19929 34981 6932 98404 3420 3525 30677 84948 610 83203 65436 1971 42386 1615 2626 4856 41088 2980 4134 38076 4919 54304 58830 4748 58403 57894 3416 56050 5645 9798 51747 94712 5267 21906 92401 581...
output:
35404
result:
ok
Test #4:
score: 0
Accepted
time: 258ms
memory: 22884kb
input:
133335 199999 1 1 86793 54950 35628 1 61213 22715 87096 1000000 24770 87096 91906 87096 85307 1000000 87096 40457 115474 1 64251 33967 6937 87096 1000000 87096 18202 92076 127416 87096 1000000 100734 87096 30258 87096 85987 6588 22068 1 6063 24322 87096 34964 1 48870 25432 87096 34653 1000000 87096 ...
output:
2.06667e+06
result:
ok
Test #5:
score: 0
Accepted
time: 190ms
memory: 23720kb
input:
133335 199999 1 1 2 1 133334 2 133332 133334 66668 1000000 1 3 2 133334 3 133330 133334 66669 1000000 1 4 3 133334 4 133328 133334 66670 1000000 1 5 4 133334 5 133326 133334 66671 1000000 1 6 5 133334 6 133324 133334 66672 1000000 1 7 6 133334 7 133322 133334 66673 1000000 1 8 7 133334 8 133320 1333...
output:
2.06667e+06
result:
ok
Test #6:
score: 0
Accepted
time: 183ms
memory: 23436kb
input:
150000 199998 1 132632 141650 4 114207 77337 4 65363 106697 1 24980 50044 1 96444 89504 1 77993 118619 1 51525 134641 1 77814 113941 1 31224 95736 1 133041 143252 1 26286 2462 1 82510 87824 4 34012 111952 1 59642 87289 4 121876 17260 1 112338 61655 4 128316 109568 1 104525 134917 1 59610 144467 4 74...
output:
149999
result:
ok
Test #7:
score: 0
Accepted
time: 107ms
memory: 22152kb
input:
150000 199998 1 1 2 1 1 4 4 2 3 1 3 4 1 4 5 1 4 7 4 5 6 1 6 7 1 7 8 1 7 10 4 8 9 1 9 10 1 10 11 1 10 13 4 11 12 1 12 13 1 13 14 1 13 16 4 14 15 1 15 16 1 16 17 1 16 19 4 17 18 1 18 19 1 19 20 1 19 22 4 20 21 1 21 22 1 22 23 1 22 25 4 23 24 1 24 25 1 25 26 1 25 28 4 26 27 1 27 28 1 28 29 1 28 31 4 29...
output:
149999
result:
ok
Test #8:
score: 0
Accepted
time: 0ms
memory: 3816kb
input:
2 1 1 1 2 1 1 1.0
output:
1
result:
ok
Test #9:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
2 1 2 1 2 1 1 1.0 2 0.9999
output:
1
result:
ok
Test #10:
score: 0
Accepted
time: 0ms
memory: 3684kb
input:
2 1 2 1 2 1 1 0.9999 2 0.9999
output:
impossible
result:
ok
Test #11:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
3 2 2 1 2 1000000 1 3 1 2 1.0 1 0.0001
output:
1.9998e+06
result:
ok
Test #12:
score: 0
Accepted
time: 0ms
memory: 3924kb
input:
3 2 2 1 2 1000000 1 3 1 2 1.0 3 0.0001
output:
1.9998e+06
result:
ok
Test #13:
score: 0
Accepted
time: 0ms
memory: 3900kb
input:
3 2 3 1 2 1000000 1 3 1 2 1.0 1 0.0001 3 0.0001
output:
1.9996e+06
result:
ok
Test #14:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
2 1 2 1 2 1 1 0.3894 2 1.0000
output:
1
result:
ok
Test #15:
score: 0
Accepted
time: 0ms
memory: 3904kb
input:
2 1 2 1 2 7 2 1.0000 1 1.0000
output:
7
result:
ok
Test #16:
score: 0
Accepted
time: 0ms
memory: 3840kb
input:
2 1 2 1 2 3 2 0.6646 1 1.0000
output:
3
result:
ok
Test #17:
score: 0
Accepted
time: 0ms
memory: 3936kb
input:
2 1 1 1 2 8 2 0.8796
output:
impossible
result:
ok
Test #18:
score: 0
Accepted
time: 0ms
memory: 3980kb
input:
3 2 2 3 1 3 2 1 1 2 0.7708 1 1.0000
output:
3
result:
ok
Test #19:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
4 3 2 1 3 4 3 2 6 2 4 9 4 0.8352 1 1.0000
output:
19
result:
ok
Test #20:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
5 5 4 1 2 2 5 1 5 5 4 9 5 3 6 1 4 4 5 0.7135 4 1.0000 2 0.3808 1 0.8090
output:
5.35442
result:
ok
Test #21:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
6 5 6 3 5 91 1 2 92 2 6 68 4 2 11 3 2 73 6 1.0000 4 0.8685 5 0.1401 1 1.0000 2 0.1158 3 0.6658
output:
160
result:
ok
Test #22:
score: 0
Accepted
time: 0ms
memory: 3748kb
input:
7 6 4 4 1 6 1 6 6 2 6 7 7 5 3 6 3 7 6 5 7 1 1.0000 6 0.4130 4 0.8624 7 0.8749
output:
16
result:
ok
Test #23:
score: -100
Wrong Answer
time: 0ms
memory: 3804kb
input:
8 7 5 6 4 4 4 3 7 1 4 3 7 8 6 6 5 7 5 2 8 6 8 2 8 0.7477 7 0.6889 3 0.7223 1 0.0429 5 1.0000
output:
12.048
result:
wrong answer