QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#721614 | #5540. City Hall | xuxuxuxuxu# | WA | 118ms | 36120kb | C++14 | 3.3kb | 2024-11-07 16:28:28 | 2024-11-07 16:28:32 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N=1e6+5;
int n,m,ans,S,T,top,head[N],dis1[N],dis2[N],vis[N],a[N],k[N],b[N],tree[N*4];
struct E{
int too,next,zh;
}edge[N*2];
struct node{
int id,val;
};
bool operator < (node a,node b)
{
return a.val>b.val;
}
void add(int a,int b,int c)
{
edge[++top].too=b;edge[top].zh=c;
edge[top].next=head[a];head[a]=top;
}
void dj1(int s)
{
for(int i=1;i<=n;i++)
{
vis[i]=0;
dis1[i]=1e16;
}
priority_queue<node>q;
dis1[s]=0;
q.push((node){s,0});
while(!q.empty())
{
int u=q.top().id;q.pop();
if(vis[u])continue;
vis[u]=1;
for(int i=head[u];i;i=edge[i].next)
{
int v=edge[i].too,w=edge[i].zh;
if(dis1[v]>dis1[u]+w)
{
dis1[v]=dis1[u]+w;
q.push((node){v,dis1[v]});
}
}
}
}
void dj2(int s)
{
for(int i=1;i<=n;i++)
{
vis[i]=0;
dis2[i]=1e16;
}
priority_queue<node>q;
dis2[s]=0;
q.push((node){s,0});
while(!q.empty())
{
int u=q.top().id;q.pop();
if(vis[u])continue;
vis[u]=1;
for(int i=head[u];i;i=edge[i].next)
{
int v=edge[i].too,w=edge[i].zh;
if(dis2[v]>dis2[u]+w)
{
dis2[v]=dis2[u]+w;
q.push((node){v,dis2[v]});
}
}
}
}
int f(int w,int x)
{
return k[w]*x+b[w];
}
void change(int nod,int l,int r,int x)
{
if(l==r)
{
if(f(x,l)>f(tree[nod],l))tree[nod]=x;
return;
}
int mid=(l+r)/2;
if(k[tree[nod]]<k[x])
{
if(f(x,mid)>f(tree[nod],mid))
{
change(nod*2,l,mid,tree[nod]);
tree[nod]=x;
}
else change(nod*2+1,mid+1,r,x);
}
if(k[tree[nod]]>k[x])
{
if(f(x,mid)>f(tree[nod],mid))
{
change(nod*2+1,mid+1,r,tree[nod]);
tree[nod]=x;
}
else change(nod*2,l,mid,x);
}
}
int query(int nod,int l,int r,int x)
{
if(l==r)return f(tree[nod],x);
int mid=(l+r)/2;
if(x<=mid)return max(f(tree[nod],x),query(nod*2,l,mid,x));
else return max(f(tree[nod],x),query(nod*2+1,mid+1,r,x));
}
signed main()
{
ans=1e18;
cin>>n>>m>>S>>T;
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=m;i++)
{
int x,y;
scanf("%lld%lld",&x,&y);
add(x,y,(a[x]-a[y])*(a[x]-a[y]));
add(y,x,(a[x]-a[y])*(a[x]-a[y]));
}
dj1(S);
dj2(T);
for(int i=head[S];i;i=edge[i].next)
{
int v=edge[i].too;
ans=min(ans,dis2[v]*2);
}
for(int i=head[T];i;i=edge[i].next)
{
int v=edge[i].too;
ans=min(ans,dis1[v]*2);
}
k[0]=b[0]=-1e12;
for(int i=1;i<=n;i++)
{
k[i]=2*a[i];
b[i]=-2*dis2[i]-a[i]*a[i];
change(1,0,100000,i);
}
for(int i=1;i<=n;i++)
{
// if(i==2)cout<<-query(1,0,100000,a[i])<<endl;
ans=min(ans,-query(1,0,100000,a[i])+2*dis1[i]+a[i]*a[i]);
}
printf("%.6lf",0.5*ans);
return 0;
}
/*
2 1 1 2
10 100
1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16080kb
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: 2ms
memory: 16336kb
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: 16160kb
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: 0
Accepted
time: 2ms
memory: 16160kb
input:
2 1 1 2 0 100000 1 2
output:
0.000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #5:
score: 0
Accepted
time: 68ms
memory: 28040kb
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.000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #6:
score: 0
Accepted
time: 52ms
memory: 26264kb
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.000000
result:
ok found '0.0000000', expected '0.0000000', error '-0.0000000'
Test #7:
score: -100
Wrong Answer
time: 118ms
memory: 36120kb
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:
41087112.500000
result:
wrong answer 1st numbers differ - expected: '1019365473.0000000', found: '41087112.5000000', error = '0.9596934'