QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#277824 | #5540. City Hall | NYCU_template# | WA | 2ms | 6160kb | C++20 | 1.6kb | 2023-12-06 23:22:00 | 2023-12-06 23:22:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
const int N = 100005;
vector<int> adj[N];
ll h[N];
int n, m;
const ll INF = 1e18;
vector<ll> Dijkstra(int src) {
vector<ll> dis(n, INF);
vector<bool> vis(n, false);
using pll = pair<ll, int>;
priority_queue<pll, vector<pll>, greater<pll>> pq;
dis[src] = 0;
pq.push({0, src});
while(!pq.empty()) {
int x = pq.top().second;
pq.pop();
if(vis[x]) continue;
vis[x] = true;
for(auto v : adj[x]) {
ll w = (h[v] - h[x]) * (h[v] - h[x]);
if(dis[v] > dis[x] + w) {
dis[v] = dis[x] + w;
pq.push({dis[v], v});
}
}
}
return dis;
}
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int s, t;
cin >> n >> m >> s >> t;
s--, t--;
for(int i = 0; i < n; i++) {
cin >> h[i];
}
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
a--, b--;
adj[a].push_back(b);
adj[b].push_back(a);
}
vector<ll> from_src = Dijkstra(s), to_dst = Dijkstra(t);
ld ans = from_src[t];
for(int i = 0; i < n; i++) {
for(auto v : adj[i]) {
for(auto u : adj[i]) {
if(v == u) continue;
ans = min(ans, from_src[v] + to_dst[u] + (h[v] * h[v]) / (ld)2.0 + (h[u] * h[u]) / (ld)2.0 - h[u] * h[v]);
}
}
}
cout << fixed << setprecision(10) << ans << "\n";
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6108kb
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: 1ms
memory: 5992kb
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: 2ms
memory: 6160kb
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: -100
Wrong Answer
time: 1ms
memory: 6152kb
input:
2 1 1 2 0 100000 1 2
output:
10000000000.0000000000
result:
wrong answer 1st numbers differ - expected: '0.0000000', found: '10000000000.0000000', error = '10000000000.0000000'