提交记录 15026


用户 题目 状态 得分 用时 内存 语言 代码长度
SyadouHayami noi18a. 【NOI2018】归程 Accepted 100 1.541 s 108700 KB C++ 2.61 KB
提交时间 评测时间
2020-11-15 16:07:42 2020-11-15 16:07:54
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
struct Edge{
	int u,v,l,val;
	Edge(){u=v=l=val=0;}
	Edge(int U,int V,int LON,int VAL){u=U,v=V,l=LON,val=VAL;}
	bool operator < (Edge another) const {return val>another.val;}
}ed[400005];
struct UnionFindSet{
	int fa[600005];
	void makeSet(int up){for(int i=0;i<=up;++i)	fa[i]=i;}
	int findSet(int x)
	{
		if(x==fa[x])	return x;
		return fa[x]=findSet(fa[x]);
	}
	void unionSet(int x,int y)
	{
		int xx=findSet(x),yy=findSet(y);
		if(xx==yy)	return ;
		fa[xx]=yy;
	}
	bool bunionSet(int x,int y)
	{
		int xx=findSet(x),yy=findSet(y);
		if(xx==yy)	return false;
		fa[xx]=yy;
		return true;
	}
}ufs;
struct node{
	int l,val;
}p[600005];
vector<int> G[600005];
vector<pair<int,int> > fc[600005];
int T,n,m,dis[600005],fa[600005][21],dep[600005];
void Dijkstra()
{
	for(int i=1;i<=2*n-1;++i)	dis[i]=1000000000;
	priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > > Q;
	Q.push(mp(0,1));
	dis[1]=0;
	while(!Q.empty())
	{
		pair<int,int> tmp=Q.top();
		Q.pop();
		if(tmp.first>dis[tmp.second])	continue;
		int now=tmp.second,value=tmp.first;
		for(unsigned int i=0;i<fc[now].size();++i)
		{
			int to=fc[now][i].second,val=fc[now][i].first;
			if(value+val<dis[to])
			{
				dis[to]=value+val;
				Q.push(mp(value+val,to));
			}
		}
	}
	for(int i=1;i<=2*n-1;++i)	p[i].l=dis[i];
}
void Kruskal()
{
	ufs.makeSet(n*2-1);
	int now=n;
	sort(ed+1,ed+1+m);
	for(int i=1;i<=m;++i)
	{
		int u=ufs.findSet(ed[i].u),v=ufs.findSet(ed[i].v);
		if(u!=v)
		{
			ufs.fa[u]=ufs.fa[v]=++now;
			G[now].push_back(u);
			G[now].push_back(v);
			p[now].val=ed[i].val;
		}
	}
}
void dfs(int now,int pre)
{
	fa[now][0]=pre;
	dep[now]=dep[pre]+1;
	for(int i=1;i<=20;++i)	fa[now][i]=fa[fa[now][i-1]][i-1];
	for(unsigned int i=0;i<G[now].size();++i)
	{
		int to=G[now][i];
		dfs(to,now);
		p[now].l=min(p[now].l,p[to].l);
	}
}
int main(){
	p[0].l=2147483647;
	scanf("%d",&T);
	while(T-->0)
	{
//		memset(p,0,sizeof p);
//		memset(fa,0,sizeof fa);
//		memset(dep,0,sizeof dep);
//		memset(dis,0,sizeof dis);
		p[0].l=2147483647;
		scanf("%d %d",&n,&m);
		for(int i=1;i<=2*n;++i)	G[i].clear(),fc[i].clear();
		for(int i=1;i<=m;++i)
		{
			int u,v,l,val;
			scanf("%d %d %d %d",&u,&v,&l,&val);
			ed[i]=Edge(u,v,l,val);
			fc[u].push_back(mp(l,v));
			fc[v].push_back(mp(l,u));
		}
		Dijkstra();
		Kruskal();
		dfs(2*n-1,0);
		int q,K,S,lastans=0;
		scanf("%d %d %d",&q,&K,&S);
		while(q-->0)
		{
			int v,s;
			scanf("%d %d",&v,&s);
			v=(v+K*lastans-1)%n+1;
			s=(s+K*lastans)%(S+1);
			int now=v;
			for(int i=20;~i;--i)	if(p[fa[now][i]].val>s)	now=fa[now][i];
			printf("%d\n",lastans=p[now].l);
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #15.847 ms33 MB + 632 KBAcceptedScore: 5

Testcase #25.88 ms33 MB + 636 KBAcceptedScore: 5

Testcase #36.05 ms33 MB + 652 KBAcceptedScore: 5

Testcase #46.079 ms33 MB + 664 KBAcceptedScore: 5

Testcase #510.979 ms34 MB + 120 KBAcceptedScore: 5

Testcase #6910.157 ms98 MB + 212 KBAcceptedScore: 5

Testcase #79.483 ms34 MB + 76 KBAcceptedScore: 5

Testcase #89.567 ms34 MB + 84 KBAcceptedScore: 5

Testcase #99.656 ms34 MB + 80 KBAcceptedScore: 5

Testcase #10676.18 ms89 MB + 888 KBAcceptedScore: 5

Testcase #11676.173 ms89 MB + 896 KBAcceptedScore: 5

Testcase #12962.613 ms102 MB + 692 KBAcceptedScore: 5

Testcase #13960.91 ms102 MB + 700 KBAcceptedScore: 5

Testcase #14961.615 ms102 MB + 712 KBAcceptedScore: 5

Testcase #1511.3 ms34 MB + 144 KBAcceptedScore: 5

Testcase #1611.381 ms34 MB + 148 KBAcceptedScore: 5

Testcase #17961.918 ms102 MB + 696 KBAcceptedScore: 5

Testcase #18962.446 ms102 MB + 700 KBAcceptedScore: 5

Testcase #191.533 s106 MB + 140 KBAcceptedScore: 5

Testcase #201.541 s106 MB + 156 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:15:38 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠