QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#80567 | #5540. City Hall | XKError | WA | 4ms | 8336kb | C++ | 1.3kb | 2023-02-24 11:34:21 | 2023-02-24 11:34:24 |
Judging History
answer
#include <bits/stdc++.h>
#define maxn 100005
#define ll long long
#define inf 1e18
using namespace std;
int n, m, s, t;
vector<int> g[maxn];
int h[maxn];
ll dis[2][maxn];
queue<int> q;
int in[maxn];
ll sqr(int x) {
return 1ll * x * x;
}
void chk() {
if (q.size() && dis[q.front()] > dis[q.back()]) swap(q.front(), q.back());
}
void spfa(int s, ll dis[]) {
for (int i = 1; i <= n; i++) dis[i] = inf;
dis[s] = 0;
q.push(s), in[s] = 1;
while (!q.empty()) {
int u = q.front(); q.pop(); chk(); in[u] = 0;
for (int v : g[u]) {
if (dis[v] > dis[u] + sqr(h[u] - h[v])) {
dis[v] = dis[u] + sqr(h[u] - h[v]);
if (!in[v]) q.push(v), in[v] = 1, chk();
}
}
}
// for (int i = 1; i <= n; i++) cout<<dis[i]<<" "; puts("");
}
int main() {
scanf("%d%d%d%d", &n, &m, &s, &t);
for (int i = 1; i <= n; i++) scanf("%d", &h[i]), h[i] <<= 1;
while (m--) {
int x, y;
scanf("%d%d", &x, &y);
g[x].push_back(y);
g[y].push_back(x);
}
spfa(s, dis[0]);
spfa(t, dis[1]);
ll ans = inf;
for (int i = 1; i <= n; i++) {
for (int x : g[i]) {
for (int y : g[i]) {
// cout<<i<<" "<<x<<" "<<y<<" "<<dis[0][x]<<" "<<dis[1][y]<<" "<<sqr(h[x] - h[y]) / 2<<endl;
ans = min(ans, dis[0][x] + dis[1][y] + sqr(h[x] - h[y]) / 2);
}
}
}
printf("%Lf\n", (long double)ans / 4.0);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 8336kb
input:
5 6 1 3 5 100 8 2 10 1 2 2 3 2 5 1 4 4 5 3 5
output:
4.500000
result:
ok found '4.5000000', expected '4.5000000', error '0.0000000'
Test #2:
score: 0
Accepted
time: 4ms
memory: 7972kb
input:
5 5 1 5 1 2 10 10 4 1 2 2 3 2 4 3 5 4 5
output:
3.000000
result:
ok found '3.0000000', expected '3.0000000', error '0.0000000'
Test #3:
score: 0
Accepted
time: 0ms
memory: 7632kb
input:
5 4 1 4 8 8 8 8 100 1 2 2 3 3 4 4 5
output:
0.000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 8176kb
input:
2 1 1 2 0 100000 1 2
output:
10000000000.000000
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '10000000000.0000000', error = '10000000000.0000000'