QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#335718#7404. Back and ForthKevin5307WA 1ms4124kbC++202.0kb2024-02-23 20:26:032024-02-23 20:26:03

Judging History

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

  • [2024-02-23 20:26:03]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:4124kb
  • [2024-02-23 20:26:03]
  • 提交

answer

//Author: Kevin
#include<bits/stdc++.h>
//#pragma GCC optimize("O2")
using namespace std;
#define ll long long
#define ull unsigned ll
#define pb emplace_back
#define mp make_pair
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
#define srt(x) sort(ALL(x))
#define rev(x) reverse(ALL(x))
#define rsrt(x) sort(rALL(x))
#define sz(x) (int)(x.size())
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define lb(v,x) (int)(lower_bound(ALL(v),x)-v.begin())
#define ub(v,x) (int)(upper_bound(ALL(v),x)-v.begin())
#define uni(v) v.resize(unique(ALL(v))-v.begin())
#define longer __int128_t
void die(string S){puts(S.c_str());exit(0);}
int p[202];
bool adj[202][202];
int d1[202][202],d2[202][202],d3[202][202];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t;
	cin>>t;
	while(t--)
	{
		int n,m,a,b;
		cin>>n>>m>>a>>b;
		for(int i=1;i<=n;i++)
			cin>>p[i];
		memset(adj,0,sizeof(adj));
		memset(d1,inf,sizeof(d1));
		memset(d2,inf,sizeof(d2));
		memset(d3,inf,sizeof(d3));
		while(m--)
		{
			int x,y;
			cin>>x>>y;
			adj[x][y]=1;
			d1[x][y]=p[y];
			d2[y][x]=p[x]+p[y];
		}
		for(int k=1;k<=n;k++)
			for(int i=1;i<=n;i++)
				for(int j=1;j<=n;j++)
					d1[i][j]=min(d1[i][j],d1[i][k]+d1[k][j]);
		d3[a][a]=p[a];
		priority_queue<array<int,3>,vector<array<int,3>>,greater<array<int,3>>> pq;
		pq.push({p[a],a,a});
		while(!pq.empty())
		{
			array<int,3> arr=pq.top();
			pq.pop();
			int x=arr[1],y=arr[2],d=arr[0];
			if(d3[x][y]!=d)
				continue;
			for(int j=1;j<=n;j++) if(adj[y][j])
			{
				int nd=d+(j!=x)*p[j];
				if(nd<d3[x][j])
				{
					d3[x][j]=nd;
					pq.push({nd,x,j});
				}
			}
			for(int j=1;j<=n;j++) if(adj[j][x])
			{
				int nd=d+(j!=y)*p[j];
				if(nd<d3[j][y])
				{
					d3[j][y]=nd;
					pq.push({nd,j,y});
				}
			}
			{
				int nd=d+d1[y][x]-p[x];
				if(nd<d3[y][x])
				{
					d3[y][x]=nd;
					pq.push({nd,y,x});
				}
			}
		}
		cout<<d3[b][b]<<endl;
	}
	return 0;
}

详细

Test #1:

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

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

input:

1
2 0 1 2
1 1

output:

1061109567

result:

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