QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#721993 | #5540. City Hall | infCraft# | WA | 305ms | 30440kb | C++17 | 3.0kb | 2024-11-07 17:24:24 | 2024-11-07 17:24:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define fori(x, y) for (int i=(x);i<=(y);++i)
#define forj(x, y) for (int j=(x);j<=(y);++j)
#define fork(x, y) for (int k=(x);k<=(y);++k)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define debug(x) cerr << #x << " = " << x << endl
const int N = 2e5+7;
ll h[N];
vector<pll> g[N];
bool vis[N];
ll dist[N][2];
struct Node {
int u;
ll dis;
int fa;
// int layer; // 在哪一层
Node(int u, ll dis, int fa): u(u), dis(dis), fa(fa) {}
};
struct cmp {
bool operator()(Node& n1, Node& n2) {
return n1.dis > n2.dis;
}
};
void dij(int s, int n, int lay) {
fori(1, n) {
vis[i] = false;
dist[i][lay] = 1e18;
}
priority_queue<Node,vector<Node>,cmp> pri;
pri.push(Node(s, 0, 0));
while (pri.size()) {
auto no = pri.top();
pri.pop();
int u = no.u;
if (vis[u]) continue;
dist[u][lay] = no.dis;
vis[u] = true;
for (auto [v, w]: g[u]) {
if (vis[v]) continue;
pri.push(Node(v, no.dis+w, u));
}
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, s, t;
cin >> n >> m >> s >> t;
fori(1, n) cin >> h[i];
fori(1, m) {
int u, v;
cin >> u >> v;
ll dis = (h[u]-h[v])*(h[u]-h[v])*2;
g[u].push_back({v, dis});
g[v].push_back({u, dis});
}
dij(s, n, 0);
dij(t, n, 1);
ll ans = min(dist[t][0], dist[s][1]);
for (auto [v, w]: g[s]) {
if (v == t) {
ans = 0;
break;
}
}
fori(1, n) {
if (i == s||i == t) continue;
if (g[i].size()>700) {
vector<bool> vis(n+1, false);
vector<ll> dist1(n+1, 1e18);
priority_queue<Node,vector<Node>,cmp> pri;
pri.push(Node(s, 0, 0));
while (pri.size()) {
auto no = pri.top();
pri.pop();
int u = no.u;
if (vis[u]) continue;
dist1[u] = no.dis;
vis[u] = true;
for (auto [v, w]: g[u]) {
if (vis[v]) continue;
if (u == i) {
pri.push(Node(v, no.dis+(h[u]-h[no.fa])*(h[u]-h[no.fa]), u));
}
else if (v == i) pri.push(Node(v, no.dis, u));
else pri.push(Node(v, no.dis+w, u));
}
}
ans = min(ans, dist1[t]);
}
else {
forj(0, g[i].size()-1) fork(j+1, g[i].size()-1) {
int u = g[i][j].first, v = g[i][k].first;
if (dist[u][0]+dist[v][1]>dist[v][0]+dist[u][1]) swap(u, v);
ans = min(ans, dist[u][0]+dist[v][1]+(h[u]-h[v])*(h[u]-h[v]));
}
}
}
cout << fixed << setprecision(10);
cout << ans/2.0 << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 9972kb
input:
5 6 1 3 5 100 8 2 10 1 2 2 3 2 5 1 4 4 5 3 5
output:
4.5000000000
result:
ok found '4.5000000', expected '4.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 2ms
memory: 10356kb
input:
5 5 1 5 1 2 10 10 4 1 2 2 3 2 4 3 5 4 5
output:
3.0000000000
result:
ok found '3.0000000', expected '3.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 10088kb
input:
5 4 1 4 8 8 8 8 100 1 2 2 3 3 4 4 5
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: 0
Accepted
time: 1ms
memory: 9960kb
input:
2 1 1 2 0 100000 1 2
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 305ms
memory: 30440kb
input:
632 199396 167 549 22513 93521 41403 35441 97617 53210 62622 4751 81863 14470 2994 93092 40432 30872 34423 36577 92540 92961 4110 14691 83321 10680 89112 80890 31108 24492 8973 42636 33792 27400 82361 85003 68940 31221 48625 276 52755 6649 34381 54399 6063 22628 17715 54052 58175 86609 82622 29917 9...
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 232ms
memory: 29368kb
input:
600 179700 396 574 83219 94660 9266 1939 32637 7117 33396 76947 42614 41001 87026 60210 25868 36044 35276 6147 36198 25195 50981 68230 32619 62563 28509 46643 43304 36195 99724 30903 77230 57923 36939 81397 17374 90947 48623 38120 48914 96481 98146 31707 9427 58735 82986 31328 94507 69081 51908 4188...
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: 0
Accepted
time: 124ms
memory: 27504kb
input:
100000 200000 66364 98254 48399 8344 35365 18555 95271 13113 75220 25062 73969 71647 58212 68205 36310 45496 6965 59960 71592 81323 44341 95796 61521 63298 77830 16145 73103 83477 85246 53680 67289 68475 64978 43576 18969 28023 22848 55164 31276 12825 70999 49142 77203 40134 88148 59337 2357 70519 8...
output:
1019365473.0000000000
result:
ok found '1019365473.0000000', expected '1019365473.0000000', error '0.0000000'
Test #8:
score: 0
Accepted
time: 103ms
memory: 27396kb
input:
100000 200000 21412 38673 24050 75090 3692 20770 26840 57646 61096 3013 66291 73437 83126 67768 92979 69169 9389 70447 17151 74737 33407 3128 78504 52736 45853 27090 64395 24808 83577 24168 38576 37445 71022 40066 34908 90579 58370 31436 69812 39811 83370 50254 6518 72740 79316 67247 22759 65630 564...
output:
0.0000000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #9:
score: -100
Wrong Answer
time: 129ms
memory: 28436kb
input:
100000 200000 75283 45047 38593 5224 81049 28255 11324 43744 51172 60916 67783 62336 96782 50029 48743 18780 32756 4774 32484 95733 17336 38046 98145 49655 68352 58308 21594 64540 11719 57827 30130 70076 95133 29886 93864 22677 28498 60413 44567 78935 64952 88954 85786 34019 75159 69192 15108 54645 ...
output:
424540660.5000000000
result:
wrong answer 1st numbers differ - expected: '6010044.5000000', found: '424540660.5000000', error = '69.6385220'