提交记录 4612


用户 题目 状态 得分 用时 内存 语言 代码长度
grary noi18a. 【NOI2018】归程 Runtime Error 5 247.133 ms 109876 KB C++ 2.58 KB
提交时间 评测时间
2018-07-26 08:16:09 2020-07-31 23:08:53
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 500005
#define inf 0x3f3f3f3f
using namespace std;

namespace Struct{
	struct temp{
		int x,y;
		bool operator<(const temp& o)const{return y>o.y;}
		temp(int a,int b){x=a,y=b;}
	};
	struct Edge{
		int v,c,nxt;
		Edge(){}
		Edge(int _v,int _n,int _c){v=_v,nxt=_n,c=_c;}
	};
	Edge e[N<<1];int head[N],tot;
	void AddEdge(int u,int v,int c){
		e[++tot]=Edge(v,head[u],c);head[u]=tot;
		e[++tot]=Edge(u,head[v],c);head[v]=tot;
	}
	struct edge{
		int u,v,c,l;
		edge(){}void init(){
			scanf("%d%d%d%d",&u,&v,&c,&l);
			AddEdge(u,v,c);
		}
		edge(int a,int b,int w,int h){u=a,v=b,c=w,l=h;}
		bool operator<(const edge& o)const{return l>o.l;}
	};
}using namespace Struct;
namespace Graph{
	int n,m;
	edge E[N];
	int dis[N];	
	void clear(){
		memset(dis,0x3f,sizeof dis);
		tot=0;memset(head,0,sizeof head);
	}
	void Dijkstra(int s){
		priority_queue<temp>q;
		dis[s]=0;q.push(temp(s,0));
		int top;
		while (!q.empty()){
			top=q.top().x;q.pop();
			for (int i=head[top];i;i=e[i].nxt){
				if(dis[e[i].v]>dis[top]+e[i].c)
					dis[e[i].v]=dis[top]+e[i].c,
					q.push(temp(e[i].v,dis[e[i].v]));
			}
		}
	}
}
namespace Deal{
	using namespace Graph;
	int fa[N],cnt,mi[N];
	int g[N][21],f[N][21],ch[N][2];
	int find(int x){
		return fa[x]==x?x:fa[x]=find(fa[x]);
	}
	int dfs(int x){
		mi[x]=inf;
		if (x<=n)return mi[x]=dis[x];
		mi[x]=min(mi[x],min(dfs(ch[x][0]),dfs(ch[x][1])));
	}
	void kruskal(){
		for (int i=0;i<=(n<<1)+1;++i)fa[i]=i;
		sort(E+1,E+m+1);
		int fx,fy;
		cnt=n;
		for (int i=1;i<=m;++i){
			fx=find(E[i].u),fy=find(E[i].v);
			if (fx==fy)continue;
			ch[++cnt][0]=fx,ch[cnt][1]=fy;
			fa[fx]=fa[fy]=f[fx][0]=f[fy][0]=cnt;
			g[fx][0]=g[fy][0]=E[i].l;
		}
		for (int j=1;j<20;++j)
			for (int i=1;i<=(n<<1)+1;++i)
				f[i][j]=f[f[i][j-1]][j-1],
				g[i][j]=min(g[i][j-1],g[f[i][j-1]][j-1]);
		dfs(cnt);
	}
	int Find(int s,int va){
		for (int i=19;~i;--i)
			if (g[s][i]>va&&g[s][i]<inf){
				s=f[s][i];
			}
		return s;
	}
	void Query(){
		int Q,k,s,lastans=0,v,p,tot,pos;
		scanf("%d%d%d",&Q,&k,&s);
		while (Q--){
			scanf("%d%d",&v,&p);
			v=(v+k*lastans-1)%n+1;
			p=(p+k*lastans)%(s+1);
			pos=Find(v,p);
			printf("%d\n",lastans=mi[pos]);
		}
	}
	void init(){
		memset(g,0x3f,sizeof g);
		memset(f,false,sizeof f);
		memset(ch,false,sizeof ch);
		memset(mi,false,sizeof mi);
		tot=0;
	}
}

int main(){
	int T;
	scanf("%d",&T);
	while (T--){
		Deal::init();
		Graph::clear();
		scanf("%d%d",&Graph::n,&Graph::m);
		for (int i=1;i<=Graph::m;++i)
			Graph::E[i].init();
		Graph::Dijkstra(1);
		Deal::kruskal();
		Deal::Query();
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #113.856 ms89 MB + 696 KBAcceptedScore: 5

Testcase #27.484 ms89 MB + 696 KBRuntime ErrorScore: 0

Testcase #37.507 ms89 MB + 704 KBRuntime ErrorScore: 0

Testcase #47.552 ms89 MB + 708 KBRuntime ErrorScore: 0

Testcase #58.427 ms89 MB + 868 KBRuntime ErrorScore: 0

Testcase #6206.812 ms106 MB + 64 KBRuntime ErrorScore: 0

Testcase #77.987 ms89 MB + 788 KBRuntime ErrorScore: 0

Testcase #87.99 ms89 MB + 788 KBRuntime ErrorScore: 0

Testcase #97.986 ms89 MB + 788 KBRuntime ErrorScore: 0

Testcase #10185.664 ms98 MB + 852 KBRuntime ErrorScore: 0

Testcase #11185.897 ms98 MB + 852 KBRuntime ErrorScore: 0

Testcase #12246.901 ms107 MB + 308 KBRuntime ErrorScore: 0

Testcase #13246.736 ms106 MB + 988 KBRuntime ErrorScore: 0

Testcase #14247.088 ms107 MB + 304 KBRuntime ErrorScore: 0

Testcase #158.595 ms89 MB + 876 KBRuntime ErrorScore: 0

Testcase #168.601 ms89 MB + 884 KBRuntime ErrorScore: 0

Testcase #17246.851 ms106 MB + 760 KBRuntime ErrorScore: 0

Testcase #18247.133 ms106 MB + 948 KBRuntime ErrorScore: 0

Testcase #19246.96 ms106 MB + 988 KBRuntime ErrorScore: 0

Testcase #20246.999 ms106 MB + 980 KBRuntime ErrorScore: 0


Judge Duck Online | 评测鸭在线
Server Time: 2026-04-13 06:27:31 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠