提交记录 4359


用户 题目 状态 得分 用时 内存 语言 代码长度
zhouzhendong noi18a. 【NOI2018】归程 Accepted 100 1.27 s 63712 KB C++ 2.56 KB
提交时间 评测时间
2018-07-20 15:35:01 2020-07-31 22:54:49
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
int read(){
	char ch=getchar();
	int x=0;
	while (!('0'<=ch&&ch<='9'))
		ch=getchar();
	while ('0'<=ch&&ch<='9')
		x=(x<<1)+(x<<3)+ch-48,ch=getchar();
	return x;
}
const int N=200005,M=400005;
int T,n,m;
struct Gragh{
	int cnt,y[M*2],z[M*2],nxt[M*2],fst[N];
	void clear(){
		cnt=0;
		memset(fst,0,sizeof fst);
	}
	void add(int a,int b,int c){
		y[++cnt]=b,z[cnt]=c,nxt[cnt]=fst[a],fst[a]=cnt;
	}
}g;
struct Edge{
	int x,y,h;
	Edge(){}
	Edge(int _x,int _y,int _h){
		x=_x,y=_y,h=_h;
	}
	friend bool operator < (Edge a,Edge b){
		return a.h>b.h;
	}
}e[M];
int dis[N],vis[N];
struct Node{
	int x,d;
	Node(){}
	Node(int _x,int _d){
		x=_x,d=_d;
	}
	friend bool operator < (Node x,Node y){
		return x.d>y.d;
	}
};
priority_queue <Node> Q;
void Dijkstra(){
	while (!Q.empty())
		Q.pop();
	for (int i=1;i<=n;i++)
		dis[i]=2e9+5;
	dis[1]=0;
	memset(vis,0,sizeof vis);
	Q.push(Node(1,0));
	while (!Q.empty()){
		Node now=Q.top();
		Q.pop();
		int x=now.x;
		if (vis[x])
			continue;
		vis[x]=1,dis[x]=now.d;
		for (int i=g.fst[x];i;i=g.nxt[i])
			Q.push(Node(g.y[i],dis[x]+g.z[i]));
	}
}
const int N2=N*2;
int fa[N2],son[N2][2],h[N2],mindis[N2],Fa[N2][20];
int getf(int x){
	return fa[x]==x?x:fa[x]=getf(fa[x]);
}
int Qu[N2],head,tail;
int main(){
	T=read();
	while (T--){
		n=read(),m=read();
		g.clear();
		for (int i=1;i<=m;i++){
			int x=read(),y=read(),l=read(),a=read();
			g.add(x,y,l);
			g.add(y,x,l);
			e[i]=Edge(x,y,a);
		}
		Dijkstra();
		sort(e+1,e+m+1);
		memset(fa,0,sizeof fa);
		for (int i=1;i<=n*2;i++)
			fa[i]=i;
		for (int i=1;i<=n;i++)
			h[i]=e[1].h+1;
		int cnt=n;
		memset(son,0,sizeof son);
		memset(h,0,sizeof h);
		for (int i=1;i<=m;i++){
			int x=getf(e[i].x),y=getf(e[i].y);
			if (x==y)
				continue;
			h[++cnt]=e[i].h;
			son[cnt][0]=x,son[cnt][1]=y;
			fa[x]=fa[y]=cnt;
		}
		head=tail=0;
		Qu[++tail]=cnt;
		while (head<tail){
			int x=Qu[++head];
			for (int i=1;i<19;i++)
				Fa[x][i]=Fa[Fa[x][i-1]][i-1];
			for (int i=0;i<2;i++){
				int y=son[x][i];
				if (y){
					Fa[y][0]=x;
					Qu[++tail]=y;
				}
			}
		}
		for (int i=tail;i>0;i--){
			int x=Qu[i];
			if (x<=n)
				mindis[x]=dis[x];
			else
				mindis[x]=min(mindis[son[x][0]],mindis[son[x][1]]);
		}
		int q=read(),K=read(),S=read();
		int lastans=0;
		h[0]=-1;
		while (q--){
			int v=read(),p=read();
			v=(v+K*lastans-1)%n+1;
			p=(p+K*lastans)%(S+1);
			for (int i=18;i>=0;i--)
				if (h[Fa[v][i]]>p)
					v=Fa[v][i];
			printf("%d\n",lastans=mindis[v]);
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #11.188 ms7 MB + 684 KBAcceptedScore: 5

Testcase #21.213 ms7 MB + 704 KBAcceptedScore: 5

Testcase #31.363 ms7 MB + 716 KBAcceptedScore: 5

Testcase #41.527 ms7 MB + 732 KBAcceptedScore: 5

Testcase #55.502 ms8 MB + 140 KBAcceptedScore: 5

Testcase #6655.021 ms57 MB + 700 KBAcceptedScore: 5

Testcase #74.211 ms8 MB + 28 KBAcceptedScore: 5

Testcase #84.238 ms8 MB + 32 KBAcceptedScore: 5

Testcase #94.227 ms8 MB + 28 KBAcceptedScore: 5

Testcase #10439.798 ms51 MB + 412 KBAcceptedScore: 5

Testcase #11440.388 ms51 MB + 416 KBAcceptedScore: 5

Testcase #12753.075 ms59 MB + 292 KBAcceptedScore: 5

Testcase #13752.208 ms59 MB + 128 KBAcceptedScore: 5

Testcase #14753.665 ms58 MB + 564 KBAcceptedScore: 5

Testcase #156.023 ms8 MB + 144 KBAcceptedScore: 5

Testcase #166.016 ms8 MB + 148 KBAcceptedScore: 5

Testcase #17752.994 ms58 MB + 828 KBAcceptedScore: 5

Testcase #18752.649 ms59 MB + 96 KBAcceptedScore: 5

Testcase #191.266 s62 MB + 224 KBAcceptedScore: 5

Testcase #201.27 s61 MB + 744 KBAcceptedScore: 5


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