提交记录 8365


用户 题目 状态 得分 用时 内存 语言 代码长度
bzh noi18a. 【NOI2018】归程 Accepted 100 1.483 s 129104 KB C++ 2.76 KB
提交时间 评测时间
2019-02-14 10:37:30 2020-08-01 01:17:40
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
struct rec{
	int l,r,w;
	long long dist;
}edge[400005];
struct node{
	int to;
	long long w;
	node *next;
}*nd[200005];
int i,j,m,n,x,y,s,q,k,v0,p0,maxlog,u,test,ii,heapcnt;
long long lastans,inf,dist[200005],cnt;
int father[400005],fathermul[400005][20],minh[400005],mindist[400005];
bool visit[200005];
int heap[200005];
void addd(int u,int v,long long w){
	node *p=new node();
	p->to=v;
	p->w=w;
	p->next=nd[u];
	nd[u]=p;
}
long long getmin(long long a,long long b){
	if (a<b) return a;
	else return b;
}
bool cmp(rec a,rec b){
	if (a.w>b.w) return true;
	else return false;
}
void move(int u){
	int temp;
	if (u>1){
		if (dist[heap[u]]<dist[heap[u>>1]]){
			temp=heap[u];
			heap[u]=heap[u>>1];
			heap[u>>1]=temp;
			move(u>>1);
			return;
		}
	}
	if (u*2==heapcnt){
		if (dist[heap[u]]>dist[heap[u<<1]]){
			temp=heap[u];
			heap[u]=heap[u<<1];
			heap[u<<1]=temp;
		}
		return;
	}
	if (u*2+1<=heapcnt){
		int tt;
		if (dist[heap[u<<1]]<dist[heap[u<<1|1]]){
			tt=u<<1;
		}else{
			tt=u<<1|1;
		}
		if (dist[heap[u]]>dist[heap[tt]]){
			temp=heap[u];
			heap[u]=heap[tt];
			heap[tt]=temp;
			move(tt);
		}
	}
}
void dij(){
	heapcnt=1;
	heap[1]=1;
	int i,u;
	for(i=2;i<=n;i++){
		dist[i]=inf;
	}
	dist[1]=0;
	node *p;
	while(heapcnt){
		u=heap[1];
		heap[1]=heap[heapcnt];
		heapcnt--;
		if (heapcnt) move(1);
		p=nd[u];
		while(p){
			if (dist[u]+p->w<dist[p->to]){
				dist[p->to]=dist[u]+p->w;
				heapcnt++;
				heap[heapcnt]=p->to;
				move(heapcnt);
			}
			p=p->next;
		}
	}
}
int getfather(int u){
	if (u==father[u]) return u;
	father[u]=getfather(father[u]);
	return father[u];
}
int main(){
scanf("%d",&test);
while(test--){
	lastans=0;
	maxlog=19;
	inf=1000000000000000000;
	scanf("%d%d",&n,&m);
	for(i=1;i<=n;i++){
		nd[i]=NULL;
	}
	for(i=1;i<=m;i++){
		scanf("%d%d%lld%d",&edge[i].l,&edge[i].r,&edge[i].dist,&edge[i].w);
		addd(edge[i].l,edge[i].r,edge[i].dist);
		addd(edge[i].r,edge[i].l,edge[i].dist);
	}
	dij();
	sort(edge+1,edge+m+1,cmp);
	for(i=1;i<=n;i++){
		father[i]=i;
		mindist[i]=dist[i];
	}
	cnt=n;
	for(i=1;i<=m;i++){
		x=getfather(edge[i].l);
		y=getfather(edge[i].r);
		if (x!=y){
			cnt++;
			father[cnt]=father[x]=father[y]=cnt;
			fathermul[x][0]=fathermul[y][0]=cnt;
			minh[cnt]=edge[i].w;
			mindist[cnt]=getmin(mindist[x],mindist[y]);//the minimum dist in the subtree of cnt;
		}
	}
	fathermul[cnt][0]=cnt;
	for(i=1;i<=maxlog;i++){
		for(j=1;j<=cnt;j++){
			fathermul[j][i]=fathermul[fathermul[j][i-1]][i-1];
		}
	}
	scanf("%d%d%d",&q,&k,&s);
	while(q--){
		scanf("%d%d",&v0,&p0);
		v0=(v0+k*lastans-1)%n+1;
		p0=(p0+k*lastans)%(s+1);
		u=v0;
		for(i=maxlog;i>=0;i--){
			if (minh[fathermul[u][i]]>p0){
				u=fathermul[u][i];
			}
		}
		lastans=mindist[u];
		printf("%lld\n",lastans);
	}
}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #112.24 us48 KBAcceptedScore: 5

Testcase #234.29 us64 KBAcceptedScore: 5

Testcase #3185.46 us88 KBAcceptedScore: 5

Testcase #4364.92 us124 KBAcceptedScore: 5

Testcase #54.737 ms1 MB + 56 KBAcceptedScore: 5

Testcase #6794.51 ms121 MB + 556 KBAcceptedScore: 5

Testcase #73.613 ms700 KBAcceptedScore: 5

Testcase #83.637 ms704 KBAcceptedScore: 5

Testcase #93.607 ms700 KBAcceptedScore: 5

Testcase #10614.235 ms81 MB + 164 KBAcceptedScore: 5

Testcase #11614.236 ms81 MB + 168 KBAcceptedScore: 5

Testcase #12941.52 ms123 MB + 148 KBAcceptedScore: 5

Testcase #13941.925 ms122 MB + 1008 KBAcceptedScore: 5

Testcase #14941.471 ms122 MB + 412 KBAcceptedScore: 5

Testcase #155.357 ms1 MB + 60 KBAcceptedScore: 5

Testcase #165.337 ms1 MB + 64 KBAcceptedScore: 5

Testcase #17941.66 ms122 MB + 684 KBAcceptedScore: 5

Testcase #18941.497 ms122 MB + 972 KBAcceptedScore: 5

Testcase #191.482 s126 MB + 80 KBAcceptedScore: 5

Testcase #201.483 s125 MB + 604 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-23 18:46:15 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用