QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#50922#4437. Link with Runningzzxzzx123RE 0ms0kbC++171.7kb2022-09-29 17:47:062022-09-29 17:47:09

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:47:09]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2022-09-29 17:47:06]
  • 提交

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],d[N],cnt;
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;
int id[N],be[N];
pii ans[N];
pair<long long ,long long> dij()
{
	for(int j=1;j<=n;j++)
	{
		//这个是拓扑的序列
		int u=be[j];
		for(int i=h[u];~i;i=ne[i]){
			int v=e[i];
			if(ans[v].first>ans[u].first+w[i])
			{
				ans[v].first=ans[u].first+w[i];
				ans[v].second=ans[u].second+val[i];
				continue;
			}
			if(ans[v].first==(ans[u].first+w[i])){
				ans[v].second=max(ans[v].second,ans[u].second+val[i]);
				continue;
			}
		} 
	}
}

int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		memset(h,-1,sizeof h);
		memset(d,0,sizeof d);
		idx=0;
		scanf("%d%d",&n,&m);
		for(int i=2;i<=n;i++){
			ans[i].first=1e15;
			ans[i].second=0;
		}		
		for(int i=1;i<=m;i++)
		{
			int u,v;
			ll e,p;//如果是没有的点的话提前进行结束 
			scanf("%d%d%lld%lld",&u,&v,&e,&p);
			d[v]++;
			add(u,v,e,p);
		}//先选择补丢弃环 
		cnt=0;
		queue<int>q;
		for(int i=1;i<=n;i++){
			if(!d[i])
			{
				q.push(i);
			}
		}
		while(!q.empty()){
			int u=q.front();
			q.pop();
			id[u]=++cnt;
			be[cnt]=u;
			for(int i=h[u];~i;i=ne[i]){
				int v=e[i];
				d[v]--;
				if(!d[v]){
					q.push(v);
				}
			} 
		}
		dij();
		printf("%lld %lld\n",ans[n].first,ans[n].second);
	}
	return 0;
} 

详细

Test #1:

score: 0
Runtime Error

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: