QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#18287#2178. Robot2022zll#0 34ms39716kbC++111.6kb2022-01-17 12:17:292022-05-04 17:40:38

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-04 17:40:38]
  • 评测
  • 测评结果:0
  • 用时:34ms
  • 内存:39716kb
  • [2022-01-17 12:17:29]
  • 提交

answer

#include<cstdio>
#include<cstring>
#include<map>
#include<queue>
typedef long long ll;
int read(){
	int ch=getchar(),num=0;
	while(ch<48||ch>57)ch=getchar();
	while(ch>=48&&ch<=57)num=(num<<3)+(num<<1)+(ch^48),ch=getchar();
	return num;
}
ll min(ll a,ll b){
	return a<b?a:b;
}
const int maxn=100005,maxm=200005;
int n,m,k,u,v,c,w;
ll S[maxn+maxm*2],dis[maxn+maxm*2];
int head[maxn+maxm*2],total;
struct Edge{
	int to,next,c,w;
}e[maxm*4];
std::map<int,int>virt[maxn+maxm*2];
void add(int u,int v,int c,int w){
	if(!virt[u].count(c)){
		virt[u][c]=++k;
		e[++total]={k,head[u],0,0};
		head[u]=total;
	}
	int t=virt[u][c];
	e[++total]={v,head[t],c,w};
	head[t]=total;
	S[t]+=w;
}
struct Node{
	int u;
	ll d;
};
bool operator<(Node a,Node b){
	return a.d!=b.d?a.d>b.d:a.u<b.u;
}
std::priority_queue<Node>q;
void update(int u,ll d){
	if(dis[u]>d){
		dis[u]=d;
		q.push(Node{u,d});
	}
}
void dijkstra(){
	q.push(Node{1,dis[1]=0});
	while(!q.empty()){
		int u=q.top().u;
		ll d=q.top().d;
		q.pop();
		if(dis[u]<d)continue;
		if(u<=n){
			if(dis[u]<=d)continue;
			for(int i=head[u];i;i=e[i].next){
				int v=e[i].to;
				for(int j=head[v];j;j=e[j].next){
					update(e[j].to,d+min((ll)e[j].w,S[v]-e[j].w));
					update(virt[e[j].to][e[j].c],d);
				}
			}
		}else
			for(int i=head[u];i;i=e[i].next){
				int v=e[i].to;
				update(v,d+S[u]-e[i].w);
			}
	}
}
int main(){
	n=k=read(),m=read();
	for(int i=1;i<=m;i++){
		u=read(),v=read(),c=read(),w=read();
		add(u,v,c,w),add(v,u,c,w);
	}
	memset(dis,63,sizeof(dis));
	dijkstra();
	printf("%lld\n",dis[n]<0x3f3f3f3f3f3f3f3f?dis[n]:-1ll);
	return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 32648kb

input:

2 1
1 2 1 10

output:

-1

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 34ms
memory: 39716kb

input:

25437 78923
921 9998 30945 1
5452 13736 24464 1
11746 24238 24464 1
10875 12958 24464 1
12267 20617 30945 1
3738 16549 35589 1
16223 16940 35589 1
1303 23059 24464 1
12424 21853 24464 1
11198 20674 35589 1
15645 19099 30945 1
8860 9441 24464 1
3609 15160 35589 1
22638 23472 24464 1
766 8991 35589 1
...

output:

-1

result:

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

Subtask #3:

score: 0
Skipped

Dependency #1:

0%