QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721435#5540. City Hallxuxuxuxuxu#WA 2ms16404kbC++143.1kb2024-11-07 16:06:142024-11-07 16:06:14

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 16:06:14]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:16404kb
  • [2024-11-07 16:06:14]
  • 提交

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=1;i<=n;i++)cout<<i<<" "<<dis1[i]<<" "<<dis2[i]<<endl;
    k[0]=b[0]=-1e9;
    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);
    }
    // cout<<tree[1]<<endl;
    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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 16096kb

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: 16404kb

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: 16112kb

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: 2ms
memory: 15984kb

input:

2 1 1 2
0 100000
1 2

output:

500000000.000000

result:

wrong answer 1st numbers differ - expected: '0.0000000', found: '500000000.0000000', error = '500000000.0000000'