QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722044 | #5540. City Hall | infCraft | WA | 2ms | 12156kb | C++17 | 2.5kb | 2024-11-07 17:34:00 | 2024-11-07 17:34:04 |
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
typedef long double ld;
const int N = 2e5+7;
ll h[N];
vector<pll> g[N];
bool vis[N][3];
ll dist[N][3];
struct Node {
int u;
ll dis;
int fa;
int layer; // 在哪一层
Node(int u, ld dis, int fa, int la): u(u), dis(dis), fa(fa), layer(la) {}
};
struct cmp {
bool operator()(Node& n1, Node& n2) {
return n1.layer == n2.layer ? n1.dis > n2.dis: n1.layer < n2.layer;
}
};
void Dijkstra(int s, int n) {
fori(1, n) {
vis[i][0] = vis[i][1] = vis[i][2] = false;
dist[i][0] = dist[i][1] = dist[i][2] = 1e18;
}
priority_queue<Node,vector<Node>,cmp> pri;
pri.push(Node(s, 0, 0, 0));
while (pri.size()) {
auto no = pri.top();
pri.pop();
if (vis[no.u][no.layer]) continue;
vis[no.u][no.layer] = true;
dist[no.u][no.layer] = no.dis;
// debug(no.u);
// debug(no.dis);
// debug(no.layer);
if (no.layer == 1) { // 刚刚转移下来
for (auto [v, b]: g[no.u]) {
if (vis[v][2]) continue;
ll dis2 = (h[no.fa]-h[v])*(h[no.fa]-h[v]);
pri.push(Node(v, no.dis+dis2, no.u, 2));
}
continue;
}
// 同一层
for (auto [v, dis]: g[no.u]) {
if (vis[v][no.layer]) continue;
pri.push(Node(v, no.dis+dis, no.u, no.layer));
}
if (no.layer == 0) { // 跳到下一层
for (auto [v, b]: g[no.u]) {
if (vis[v][1]) continue;
pri.push(Node(v, no.dis, no.u, 1));
}
}
}
}
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});
}
Dijkstra(s, n);
cout << fixed << setprecision(10);
cout << min({dist[t][0]/2.0l, dist[t][1]/2.0l, dist[t][2]/2.0l})+1e-10 << endl;
// cout << dist[t][2]/2.0l << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 12156kb
input:
5 6 1 3 5 100 8 2 10 1 2 2 3 2 5 1 4 4 5 3 5
output:
4.5000000001
result:
ok found '4.5000000', expected '4.5000000', error '0.0000000'
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 9956kb
input:
5 5 1 5 1 2 10 10 4 1 2 2 3 2 4 3 5 4 5
output:
65.0000000001
result:
wrong answer 1st numbers differ - expected: '3.0000000', found: '65.0000000', error = '20.6666667'