QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#50920#4437. Link with Runningzzxzzx123RE 0ms0kbC++171.5kb2022-09-29 17:27:172022-09-29 17:27:18

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-09-29 17:27:18]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-09-29 17:27:17]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<ll,ll>
const int N=3e5+50;
int h[N],e[N],ne[N],idx,vis[N];
ll w[N],val[N];
void add(int u,int v,ll c,ll d){
	e[idx]=v,ne[idx]=h[u],w[idx]=c,val[idx]=d,h[u]=idx++;
}

struct node{
	int u;
	ll e,p;
	bool operator<(const node& a)const {
		if(e!=a.e){
			return e>a.e;
		}
		//p大的在前面 
		return p<a.p;
	}
};

int n,m;

pii ans[N];

pair<long long ,long long> dij()
{
	priority_queue<node>q;
	q.push({1,0,0});
	while(!q.empty()){
		auto a=q.top();
		int u=a.u,ee=a.e,p=a.p;
		q.pop();
		if(vis[u])	continue;
		vis[u]=1;
		if(u==n){
			return {ee,p};
		}
		for(int i=h[u];~i;i=ne[i]){
			int v=e[i];
			if(vis[v])	continue;
			if(ans[v].first<ee+w[i])
			{
				ans[v]={ee+w[i],p+val[i]};
				q.push({v,ans[v].first,ans[v].second});
				continue;
			}
			if(ans[v].first==(ee+w[i]))
			{
				if(ans[v].second<p+val[i]){
					ans[v].second=p+val[i];
					q.push({v,ans[v].first,ans[v].second});
					continue;
				}
			}
		}
	}
}

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		memset(h,-1,sizeof h);
		memset(vis,0,sizeof vis);
		memset(ans,0,sizeof ans);
		idx=0;
		scanf("%d%d",&n,&m);
		for(int i=1;i<=m;i++)
		{
			int u,v;
			ll e,p;//如果是没有的点的话提前进行结束 
			scanf("%d%d%lld%lld",&u,&v,&e,&p);
			add(u,v,e,p);
		}//先选择补丢弃环 
		auto ans=dij();
		printf("%lld %lld\n",ans.first,ans.second);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Dangerous Syscalls

input:

12
100000 200000
1 2 838279516 902819511
1 3 293478832 513256010
2 4 682688353 204481674
2 5 360092507 651108247
5 6 519851939 323803002
6 7 675439277 205804465
7 8 419167205 386168059
6 9 140767493 382483305
9 10 558115401 613738466
9 11 902235661 744659643
9 12 851394758 1720015
12 13 635355827 46...

output:


result: