提交记录 4310


用户 题目 状态 得分 用时 内存 语言 代码长度
yzyyylx noi18a. 【NOI2018】归程 Accepted 100 1.738 s 120804 KB C++11 1.89 KB
提交时间 评测时间
2018-07-19 20:21:47 2020-07-31 22:51:38
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#define ll long long
#define P pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define N 400100
using namespace std;

ll n,m,T,faz[N],tt,d[N],fa[N][20],h[N],Q,K,S,last;
P tmp;
struct Bn
{
	ll u,v,a;
	bool operator < (const Bn &u) const
	{
		return a>u.a;
	}
}bn[N];
priority_queue<P,vector<P>,greater<P> >pq;
vector<P>to[N];

ll ff(ll u){return u==faz[u]?u:faz[u]=ff(faz[u]);}
inline ll find(ll u,ll v)
{
	ll i,t;
	for(i=19;i>=0;i--)
	{
		t=fa[u][i];
		if(h[t]>v) u=t;
	}
	return u;
}

int main()
{
	ll i,j,p,q,t;
	cin>>T;
	while(T--)
	{
		last=0;
		memset(d,0x3f,sizeof(d));
		memset(fa,0,sizeof(fa));
		scanf("%lld%lld",&n,&m);
		tt=n;
		for(i=1;i<2*n;i++) faz[i]=i;
		for(i=1;i<=m;i++)
		{
			scanf("%lld%lld%lld%lld",&bn[i].u,&bn[i].v,&t,&bn[i].a);
			to[bn[i].u].push_back(mp(bn[i].v,t));
			to[bn[i].v].push_back(mp(bn[i].u,t));
		}
		d[1]=0;
		pq.push(mp(0,1));
		for(;!pq.empty();)
		{
			tmp=pq.top();
			pq.pop();
			p=tmp.fi,q=tmp.se;
			if(d[q]<p) continue;
			for(i=0;i<to[q].size();i++)
			{
				t=to[q][i].fi;
				if(p+to[q][i].se>=d[t]) continue;
				d[t]=p+to[q][i].se;
				pq.push(mp(d[t],t));
			}
		}
//		for(i=1;i<=n;i++) cout<<d[i]<<" ";puts("");
		
		sort(bn+1,bn+m+1);
		for(i=1;i<=m;i++)
		{
			p=ff(bn[i].u),q=ff(bn[i].v);
			if(p==q) continue;
			tt++;
			h[tt]=bn[i].a;
			d[tt]=min(d[p],d[q]);
			fa[p][0]=fa[q][0]=tt;
			faz[p]=faz[q]=tt;
//			cout<<" "<<tt<<" "<<p<<endl<<" "<<tt<<" "<<q<<endl;
		}
		for(i=1;(1 << i)<=tt;i++)
		{
			for(j=1;j<=tt;j++)
			{
				fa[j][i]=fa[fa[j][i-1]][i-1];
			}
		}
//		for(i=1;i<=tt;i++) cout<<fa[i][1]<<" ";puts("");
		
		scanf("%lld%lld%lld",&Q,&K,&S);
		for(i=1;i<=Q;i++)
		{
			scanf("%lld%lld",&p,&q);
			p=(p+K*last-1)%n+1;
			q=(q+K*last)%(S+1);
			p=find(p,q);
			printf("%lld\n",d[p]);
			last=d[p];
		}
		
		for(i=1;i<=n;i++) to[i].clear();
	}
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #111.535 ms73 MB + 308 KBAcceptedScore: 5

Testcase #211.561 ms73 MB + 312 KBAcceptedScore: 5

Testcase #311.77 ms73 MB + 328 KBAcceptedScore: 5

Testcase #411.908 ms73 MB + 340 KBAcceptedScore: 5

Testcase #516.401 ms73 MB + 692 KBAcceptedScore: 5

Testcase #6962.55 ms113 MB + 448 KBAcceptedScore: 5

Testcase #715.085 ms73 MB + 504 KBAcceptedScore: 5

Testcase #815.081 ms73 MB + 508 KBAcceptedScore: 5

Testcase #915.074 ms73 MB + 504 KBAcceptedScore: 5

Testcase #10766.224 ms95 MB + 196 KBAcceptedScore: 5

Testcase #11766.728 ms95 MB + 200 KBAcceptedScore: 5

Testcase #121.103 s115 MB + 44 KBAcceptedScore: 5

Testcase #131.103 s114 MB + 904 KBAcceptedScore: 5

Testcase #141.103 s114 MB + 304 KBAcceptedScore: 5

Testcase #1516.859 ms73 MB + 696 KBAcceptedScore: 5

Testcase #1616.88 ms73 MB + 700 KBAcceptedScore: 5

Testcase #171.104 s114 MB + 580 KBAcceptedScore: 5

Testcase #181.103 s114 MB + 876 KBAcceptedScore: 5

Testcase #191.733 s117 MB + 996 KBAcceptedScore: 5

Testcase #201.738 s117 MB + 508 KBAcceptedScore: 5


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