QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#211530#7404. Back and ForthSolitaryDream#WA 1ms3704kbC++172.1kb2023-10-12 17:55:162023-10-12 17:55:17

Judging History

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

  • [2023-10-12 17:55:17]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3704kb
  • [2023-10-12 17:55:16]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

using tii=tuple<int,int,int>;

using pti=pair<int,tuple<int,int,int> >;

const int N=211;

int n,T,m,s,t;

int f[N][N],p[N];

int d[N][N][2];

priority_queue<pti,vector<pti>,greater<pti> >q;

int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d%d%d%d",&n,&m,&s,&t);
        for(int i=1;i<=n;i++)
            scanf("%d",&p[i]);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                f[i][j]=(i==j?0:1e9);
        for(int i=1;i<=m;i++)
        {
            int u,v;
            scanf("%d%d",&u,&v);
            f[u][v]=0;
        }
        for(int k=1;k<=n;k++)
            for(int i=1;i<=n;i++)
                for(int j=1;j<=n;j++)
                    f[i][j]=min(f[i][j],f[i][k]+f[k][j]+p[k]);
        for(int i=1;i<=n;i++)
            for(int j=1;j<=n;j++)
                for(int k=0;k<2;k++)
                    d[i][j][k]=1e8;
        d[s][s][0]=p[s];
        q.push({p[s],{s,s,0}});
        while(!q.empty())
        {
            auto [dis,Z]=q.top();
            q.pop();
            auto [x,y,z]=Z;
            if(dis!=d[x][y][z])
                continue;
            for(int u=1;u<=n;u++)
            {
                if(z==0)
                {
                    int nx=x;
                    int ny=u;
                    int nz=z^1;
                    if(d[nx][ny][nz]>d[x][y][z]+f[y][u]+p[u]*(u!=y))
                        d[nx][ny][nz]=d[x][y][z]+f[y][u]+p[u]*(u!=y),q.push({d[nx][ny][nz],{nx,ny,nz}});
                }
                else
                {
                    int nx=y;
                    int ny=u;
                    int nz=z^1;
                    if(d[nx][ny][nz]>d[x][y][z]+f[u][x]+f[y][u]+p[u]*(u!=y))
                    {
                        d[nx][ny][nz]=d[x][y][z]+f[u][x]+f[y][u]+p[u]*(u!=y),q.push({d[nx][ny][nz],{nx,ny,nz}});
                    }
                }
            }
        }
        int ans=d[t][t][0];
        if(ans>1e8)
            puts("-1");
        else
            printf("%d\n",ans);
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3704kb

input:

3
4 5 1 4
1 1 1 1
1 2
2 3
3 1
4 2
3 4
4 4 1 2
1 1 1 1
1 2
2 3
3 4
4 1
4 8 1 3
1 100 1 1
1 2
2 1
2 3
3 2
1 4
4 1
3 4
4 3

output:

4
4
3

result:

ok 3 number(s): "4 4 3"

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 3624kb

input:

1
2 0 1 2
1 1

output:

100000000

result:

wrong answer 1st numbers differ - expected: '-1', found: '100000000'