提交记录 4294


用户 题目 状态 得分 用时 内存 语言 代码长度
Iking noi18a. 【NOI2018】归程 Runtime Error 5 228.977 ms 589628 KB C++ 2.50 KB
提交时间 评测时间
2018-07-19 19:34:34 2020-07-31 22:51:11
#include <cstdio>
#include <cctype>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define clear(a) fo(ii,1,n)a[ii]=0
#define rep(i,x) for(edg *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<<1;
const ll inf=0x7FFFFFFF; 
int T,i,n,m,u,v,a,ii,x,y,num,Q,K,S,v0,p0,p;
ll l,ans,dis[N];
struct edge
{
	int u,v,a;
	ll l;
}e[M];
struct edg
{
	int to;
	ll l;
	edg *ne;
	inline edg(int to,ll l,edg *ne) : to(to), l(l), ne(ne){}
}*fin[N];

template <class T> inline void read(T &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 edg(y,l,fin[x]);
}

struct node
{
	int i; ll dis;
	inline node(int _i,ll _dis){i=_i; dis=_dis;}
};
struct cmp1
{  
    inline bool operator ()(const node &a,const node &b){return a.dis>b.dis;}  
};  
priority_queue <node,vector<node>,cmp1> P;
bool vis[N];
void dijkstra()
{
	while(!P.empty())P.pop();	P.push(node(1,0));
	clear(vis);	
	memset(dis,127,sizeof dis);   dis[1]=0;
	
	while(!P.empty())
	{
		node t=P.top();	P.pop();
		int x=t.i; ll d=t.dis;
		if(vis[x]) continue;
		vis[x]=1;
		rep(i,fin[x])
		{
			y=i->to; l=i->l;
			if(!vis[y]&&dis[y]>d+l)
			{
				dis[y]=d+l;
				P.push(node(y,dis[y]));
			}
		}
	}
}

int fa[N],fu,fv,L[N],R[N],anc[N][18],low[N][18];
ll mi[N];
inline bool cmp(edge a,edge b){return a.a>b.a;}
int gef(int x)
{
	return fa[x]==x ? x : fa[x]=gef(fa[x]);
}
void kruskal()
{
	sort(e+1,e+m+1,cmp);
	int i;
	fo(i,1,n) fa[i]=i;
	fo(i,1,m)
	{
		u=e[i].u; v=e[i].v;
		fu=gef(u);fv=gef(v);
		if(fu!=fv)
		{
			anc[fu][0]=fa[fu]=anc[fv][0]=fa[fv]=fa[num+1]=++num;
			low[fu][0]=low[fv][0]=e[i].a;
			L[num]=fu; R[num]=fv;
		}
	}
}
void dfs(int x)
{
	int i,f=anc[x][0]; mi[x]=dis[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];
	}
	if(L[x]) dfs(L[x]), MIN(mi[x],mi[L[x]]);
	if(R[x]) dfs(R[x]), MIN(mi[x],mi[R[x]]);
}

int main()
{
	for(read(T);T;T--)
	{
		read(n); read(m);
		clear(fin);
		fo(i,1,m) 
		{
			read(u), read(v), read(l), read(a);
			e[i].u=u,e[i].v=v,e[i].l=l,e[i].a=a;
			link(u,v); link(v,u);
		}
		
		dijkstra();
		
		num=n; kruskal();
		
		dfs(num);
		
		read(Q); read(K); read(S);
		fo(i,1,Q)
		{
			read(v0); v=(v0+K*ans-1)%n+1;
			read(p0); p=(p0+K*ans)%(S+1);
			fd(ii,17,0) if( anc[v][ii] && low[v][ii]>p ) v=anc[v][ii];
			printf("%lld\n",ans=mi[v]);
		}
	}
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1205.43 us1 MB + 576 KBAcceptedScore: 5

Testcase #2100.356 ms545 MB + 308 KBRuntime ErrorScore: 0

Testcase #364.669 ms545 MB + 316 KBRuntime ErrorScore: 0

Testcase #499.713 ms545 MB + 324 KBRuntime ErrorScore: 0

Testcase #568.887 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #6192.187 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #768.279 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #899.657 ms545 MB + 320 KBRuntime ErrorScore: 0

Testcase #969.231 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #10127.714 ms545 MB + 408 KBRuntime ErrorScore: 0

Testcase #11164.999 ms545 MB + 384 KBRuntime ErrorScore: 0

Testcase #12227.991 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #13228.324 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #14227.33 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #1571.542 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #1669.522 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #17227.963 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #18228.977 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #19227.567 ms575 MB + 828 KBRuntime ErrorScore: 0

Testcase #20227.544 ms575 MB + 828 KBRuntime ErrorScore: 0


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