QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722408 | #5540. City Hall | Suhy | WA | 2ms | 11032kb | C++14 | 3.2kb | 2024-11-07 18:54:09 | 2024-11-07 18:54:11 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define lb(x) ((x) & (-(x)))
#define pii pair<ll, ll>
#define pll pair<ll, ll>
#define st first
#define nd second
#define ld long double
using namespace std;
int read()
{
int x = 0, c = 0;
while('0' > c || c > '9')
c = getchar();
while('0' <= c && c <= '9')
x = x * 10 + c - '0', c = getchar();
return x;
}
const int maxn = 100005;
int n, m, s, t;
ll h[maxn];
vector <int> pic[maxn];
ll sps[maxn], spt[maxn];
priority_queue <pll, vector<pll>, greater<pll> > que;
int vis[maxn];
ll calc(int x, int y)
{return (h[x] - h[y]) * (h[x] - h[y]);}
void dij(ll *sp, int s)
{
for(int i = 1; i <= n; i ++)
sp[i] = 100000000000000000LL;
sp[s] = 0;
que.push({0, s});
while(que.size())
{
ll in = que.top().nd;
que.pop();
if(vis[in]) continue;
vis[in] = 1;
for(int i : pic[in])
{
if(sp[i] > sp[in] + calc(in, i))
{
sp[i] = sp[in] + calc(in, i);
que.push({sp[i], i});
}
}
}
memset(vis, 0, sizeof vis);
}
pair <ld, ld> q[maxn];
int l, r;
ld pnt[maxn];
ld getp(pair <ld, ld> a, pair <ld, ld> b)
{
return (b.nd - a.nd) / (a.st - b.st);
}
ld getans(pair <ld, ld> l, ll x)
{
return l.st * x + l.nd;
}
ld ans = 100000000000000000LL;
void sol(ll *a, ll *b)
{
for(int i = 1; i <= n; i ++)
{
if(i == s || i == t)
continue;
l = 1, r = 0;
for(int j : pic[i])
{
//cout<<j<<endl;
while(r - l + 1 > 1 && pnt[l + 1] <= h[j])
l ++;
if(r >= l) ans = min(ans, getans(q[l], h[j]) + (ld)0.5 * h[j] * h[j] + b[j]);
pair <ld, ld> lin = {-h[j], (ld) a[j] + (ld)0.5 * h[j] * h[j]};
while(r - l + 1 > 1)
{
int flag = 0;
if(q[r].st == lin.st)
{
flag = (lin.nd <= q[r].nd);
}
else
{
ld npt = getp(q[r], lin);
if(npt < pnt[r]) flag = 1;
}
if(flag) r --;
else break;
}
if((r == l) && ((q[r].st == lin.st) && (lin.nd <= q[r].nd)))
r --;
q[++ r] = lin;
if(r > l) pnt[r] = getp(lin, q[r - 1]);
else pnt[r] = 0;
}
}
}
bool _Cmp(int x, int y)
{return h[x] < h[y];}
signed main()
{
cin>>n>>m>>s>>t;
for(int i = 1; i <= n; i ++)
h[i] = read();
for(int i = 1; i <= m; i ++)
{
int u = read();
int v = read();
pic[u].push_back(v);
pic[v].push_back(u);
}
dij(sps, s);
dij(spt, t);
for(int i = 1; i <= n; i ++)
sort(pic[i].begin(), pic[i].end(), _Cmp);
for(int i : pic[s])
ans = min(ans, (ld) spt[i]);
for(int i : pic[t])
ans = min(ans, (ld) sps[i]);
cout<<ans<<endl;
sol(sps, spt);
sol(spt, sps);
cout<<fixed<<setprecision(10)<<ans<<endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 11032kb
input:
5 6 1 3 5 100 8 2 10 1 2 2 3 2 5 1 4 4 5 3 5
output:
68 4.5000000000
result:
wrong answer 1st numbers differ - expected: '4.5000000', found: '68.0000000', error = '14.1111111'