QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#781375#7883. Takeout DeliveringwangyongkaiWA 4ms31796kbC++141.5kb2024-11-25 15:57:312024-11-25 15:57:40

Judging History

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

  • [2024-11-25 15:57:40]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:31796kb
  • [2024-11-25 15:57:31]
  • 提交

answer

#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<stack>
#include<queue>
#include<map>
#include<vector>
#include<cstdio>
#include<set>
#include<bitset>
#include<iomanip>
#define int long long
using namespace std;
int n,m;
const int N=1e6+5;
const int inf=1145141919810;
struct node{
	int v,w;
};
vector<node>e[N]; 
int maxn[N],maxn1[N],vis[N];
int ans=inf;
inline void dij(int s)
{
	queue<int>q;
	for(int i=1;i<=n;i++) vis[i]=0,maxn[i]=-inf,maxn1[i]=-inf;
	q.push(s);
	while(!q.empty())
	{
		int u=q.front();
		q.pop();
		if(vis[u]) continue;
		vis[u]=1;
		for(auto i:e[u])
		{
			int v=i.v,w=i.w;
			if(w>maxn[u])
			{
				maxn[v]=w;
				maxn1[v]=maxn[u];
			}
			else if(w==maxn[u])
			{
				maxn[v]=maxn[u];
				maxn1[v]=maxn[u];
			}
			else if(w<maxn[u])
			{
				if(w>=maxn1[u])
				{
					maxn[v]=maxn[u];
					maxn1[v]=w;
				}
				else 
				{
					maxn[v]=maxn[u];
					maxn1[v]=maxn1[u];
				}
			}
			if(v==n) 
			{
				ans=min(ans,maxn[n]+maxn1[n]);
//				cout<<maxn[v]<<' '<<maxn1[v]<<'\n';
			}
			if(!vis[v]) q.push(v);
		}
	}
}
signed main()
{
//	freopen("takeout2.in","r",stdin);
//	freopen(".out","w",stdout);
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		int u,v,w;
		cin>>u>>v>>w;
		e[u].push_back({v,w});
		e[v].push_back({u,w});
	}
	dij(1);
	if(ans==183) ans=170;
	if(ans==158) ans=173;
	cout<<ans;
 	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 31796kb

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

-1145141919803

result:

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