提交记录 3945


用户 题目 状态 得分 用时 内存 语言 代码长度
Iking noi18a. 【NOI2018】归程 Wrong Answer 5 4 s 579936 KB C++ 2.24 KB
提交时间 评测时间
2018-07-18 20:04:14 2020-07-31 22:06:02
#include <bits/stdc++.h>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define init(a) fo(ii,1,n)a[ii]=inf
#define clear(a) fo(ii,1,n)a[ii]=0
#define rep(i,x) for(edge *i=x; i; i=i->ne)
#define MIN(x,y) x=min(x,y)
using namespace std;
typedef long long ll;

const int N=2e5+1,M=N<<2;
const ll inf=0x7FFFFFFF;
int T,i,n,m,u,v,l,a,Q,K,S,v0,p0,p,st,en,q[10*N],x;
bool onekind,exist[N],vis[N],tree;
ll dis[N],ans;
struct edge
{
	int to,a;
	ll l;
	edge *ne;
	edge(int to,ll l,int a,edge *ne) : to(to), l(l), a(a), ne(ne){}
}*fin[N];

inline void read(int &x)
{
	char ch=getchar(); x=0;
	for(;!isdigit(ch);ch=getchar());
	for(;isdigit(ch);ch=getchar()) x=(x<<3)+(x<<1)+(ch^48);
}

inline void link(int x,int y)
{
	fin[x]=new edge(y,l,a,fin[x]);
}

void spfa(int x)
{
	int ii,y;
	init(dis);    dis[x]=0;
	clear(exist); exist[x]=1;
	st=0; q[en=1]=x;
	while(st<en)
	{
		x=q[++st];
		rep(i,fin[x])
		{
			y=i->to;
			if(dis[y]<=dis[x]+i->l) continue;
			dis[y]=dis[x]+i->l;
			if(!exist[y])
			{
				exist[y]=1; q[++en]=y;
				if(dis[y]<dis[q[st+1]]) swap(q[en],q[st+1]);
			}
		}
		exist[x]=0;
	}
}

void flood(int x)
{
	vis[x]=1;
	rep(i,fin[x]) 
		if(i->a>p)
		{
			int y=i->to;
			if(!vis[y]) flood(y);
		}
}//get visitable vertexes

int fa[N],anc[N][18],low[N][18];
ll len[N];
void dfs(int x)
{
	int i,f;
	f=anc[x][0]=fa[x];
	fo(i,1,17)
	{
		if(!f) break;
		low[x][i]=min(low[x][i-1],low[f][i-1]);
		f=anc[x][i]=anc[f][i-1];
	}
	
	rep(i,fin[x])
	{
		int y=i->to;
		if(y==fa[x]) continue;
		fa[y]=x; low[y][0]=i->a; 
		len[y]=len[x]+i->l; dfs(y);
	}
}

int main()
{
	for(read(T);T;T--)
	{
		read(n); read(m); 
		onekind=1; tree=(m==n-1);
		fo(i,1,m)
		{
			read(u); read(v); read(l); read(a);
			link(u,v); link(v,u);
			onekind&=(a==1);
		}
		read(Q); read(K); read(S);
		
		if(onekind) spfa(1);
		else
		if(tree) dfs(1);
		
		fo(i,1,Q) 
		{
			read(v0); read(p0);
			
			if(onekind)
			{
				printf("%lld\n",(p0>0)*dis[v0]);
				continue;
			}
			
			v=(v0+K*ans-1)%n+1;
			p=(p0+K*ans)%(S+1);
			int ii;
			
			if(tree)
			{
				fd(ii,17,0) if( anc[v][ii] && low[v][ii]>p ) v=anc[v][ii];
				printf("%lld\n",ans=len[v]);
				continue;
			}
			
			clear(vis);
			flood(v);	
			spfa(1);
			ans=inf;
			fo(x,1,n) if(vis[x]) MIN(ans,dis[x]);
			printf("%lld\n",ans);
		}	
	}
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #135.9 us52 KBAcceptedScore: 5

Testcase #254.04 us64 KBWrong AnswerScore: 0

Testcase #3150.79 us80 KBWrong AnswerScore: 0

Testcase #4235.95 us100 KBWrong AnswerScore: 0

Testcase #53.042 ms776 KBWrong AnswerScore: 0

Testcase #6485.083 ms34 MB + 336 KBRuntime ErrorScore: 0

Testcase #74 s600 KBTime Limit ExceededScore: 0

Testcase #84 s600 KBTime Limit ExceededScore: 0

Testcase #94 s600 KBTime Limit ExceededScore: 0

Testcase #103.77 s566 MB + 348 KBRuntime ErrorScore: 0

Testcase #113.775 s566 MB + 352 KBRuntime ErrorScore: 0

Testcase #12529.061 ms35 MB + 484 KBRuntime ErrorScore: 0

Testcase #13525.682 ms35 MB + 760 KBRuntime ErrorScore: 0

Testcase #14488.554 ms34 MB + 468 KBRuntime ErrorScore: 0

Testcase #152.46 s804 KBWrong AnswerScore: 0

Testcase #162.588 s808 KBWrong AnswerScore: 0

Testcase #17528.993 ms35 MB + 416 KBRuntime ErrorScore: 0

Testcase #18528.439 ms35 MB + 284 KBRuntime ErrorScore: 0

Testcase #19525.284 ms35 MB + 528 KBRuntime ErrorScore: 0

Testcase #20533.412 ms35 MB + 228 KBRuntime ErrorScore: 0


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