QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#50929#4437. Link with Runningzzxzzx123WA 729ms15460kbC++171.7kb2022-09-29 18:49:222022-09-29 18:49:24

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 18:49:24]
  • 评测
  • 测评结果:WA
  • 用时:729ms
  • 内存:15460kb
  • [2022-09-29 18:49:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pii pair<ll,ll>
const int N=3e5+50;
const ll inf=1e17;
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];
void dij()
{
	for(int j=1;j<=n;j++)
	{
		//这个是拓扑的序列
		int u=be[j];
		if(ans[u].first==inf)	continue;
		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=inf;
			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);
				}
			} 
		}
		cout<<(cnt==n)<<endl;
		dij();
		printf("%lld %lld\n",ans[n].first,ans[n].second);
	}
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 729ms
memory: 15460kb

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:

0
100000000000000000 0
0
100000000000000000 0
1
2522027 438209666288
0
100000000000000000 0
1
249512452 24966236662852
0
100000000000000000 0
0
100000000000000000 0
1
0 1000000000
0
100000000000000000 0
0
100000000000000000 0
0
100000000000000000 0
0
100000000000000000 0

result:

wrong answer 1st lines differ - expected: '5927443549 11285847934', found: '0'