提交记录 21557


用户 题目 状态 得分 用时 内存 语言 代码长度
rzh123 noi18a. 【NOI2018】归程 Accepted 100 1.35 s 72120 KB C++ 2.28 KB
提交时间 评测时间
2024-04-12 18:53:39 2024-04-12 18:53:57
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr int N=4e5+5,M=4e5+5;
constexpr long long INF{0x3F3F3F3F3F3F3F3Fll};
int n,m,q,kk,ss,ec,eh[N],nc;
int dep[N],w[N],fa[N][20];
long long dis[N],mn[N];
struct EI{int u,v,w;}ei[M];
struct{int nxt,to,dis,h;}e[M<<1];
struct{
	int fa[N];
	inline void init(int n){
		iota(fa+1,fa+n+1,1);
	}
	int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
	inline void merge(int x,int y){
		if((x=find(x))==(y=find(y))) return ;
		fa[x]=y;
	}
}dsu;
inline void adde(int u,int v,int w,int h){
	e[++ec]={eh[u],v,w,h},eh[u]=ec;
}
void dij(int s){
	using Q=pair<long long,int>;
	vector<bool> vst(n+5,false);
	priority_queue<Q,vector<Q>,greater<Q> > q;
	memset(dis,0x3f,sizeof dis);
	q.emplace(dis[s]=0,s);
	while(!q.empty()){
		int u{q.top().second}; q.pop();
		if(vst[u]) continue;
		vst[u]=true;
		for(int i{eh[u]};i;i=e[i].nxt){
			int v{e[i].to},w{e[i].dis};
			if(dis[u]+w<dis[v])
				q.emplace(dis[v]=dis[u]+w,v);
		}
	}
}
void krus(){
	nc=n;
	fill(w+1,w+nc+1,INF);
	memset(eh+1,0,n*sizeof(int)),ec=0;
	sort(ei+1,ei+m+1,[](const EI &a,const EI &b){return a.w>b.w;});
	dsu.init(n*2);
	for(int i{1};i<=m;++i){
		int u{ei[i].u},v{ei[i].v},w{ei[i].w};
		u=dsu.find(u),v=dsu.find(v);
		if(u!=v){
			int t{++nc};
			::w[t]=w;
			adde(t,u,0,0),adde(t,v,0,0);
			dsu.merge(u,t),dsu.merge(v,t);
		}
	}
}
void dfs(int u,int fa){
	for(int i{0};i<=20;++i) ::fa[u][0]=0;
	dep[u]=dep[::fa[u][0]=fa]+1;
	mn[u]=(u<=n)?dis[u]:INF;
	for(int i{1};i<=__lg(dep[u]);++i)
		::fa[u][i]=::fa[::fa[u][i-1]][i-1];
	for(int i{eh[u]};i;i=e[i].nxt){
		int v{e[i].to};
		if(v==fa) continue;
		dfs(v,u);
		mn[u]=min(mn[u],mn[v]);
	}
}
int findw(int u,int lim){
	for(int i{__lg(dep[u])};i>=0;--i){
		if(fa[u][i]&&w[fa[u][i]]>lim)
			u=fa[u][i];
	}
	return u;
}
int main(){
	cin.tie(0)->sync_with_stdio(0);
	int tc; cin>>tc;
	while(tc--){
		cin>>n>>m;
		memset(fa,0,sizeof fa);
		memset(w,0,sizeof w);
		memset(eh+1,0,n*2*sizeof(int)),ec=nc=0;
		for(int i{1};i<=m;++i){
			int u,v,w,h; cin>>u>>v>>w>>h;
			ei[i]={u,v,h};
			adde(u,v,w,h);
			adde(v,u,w,h);
		}
		dij(1);
		krus();
		dfs(nc,0);
		cin>>q>>kk>>ss;
		long long lsta{0};
		while(q--){
			int s,p; cin>>s>>p;
			if(kk){
				s=int((s+lsta-1)%n+1);
				p=int((p+lsta)%(ss+1));
			}
			int u{findw(s,p)};
			cout<<(lsta=mn[u])<<'\n';
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #15.478 ms35 MB + 176 KBAcceptedScore: 5

Testcase #25.468 ms35 MB + 184 KBAcceptedScore: 5

Testcase #35.63 ms35 MB + 204 KBAcceptedScore: 5

Testcase #45.777 ms35 MB + 212 KBAcceptedScore: 5

Testcase #59.734 ms35 MB + 480 KBAcceptedScore: 5

Testcase #6758.82 ms62 MB + 492 KBAcceptedScore: 5

Testcase #78.43 ms35 MB + 384 KBAcceptedScore: 5

Testcase #88.436 ms35 MB + 392 KBAcceptedScore: 5

Testcase #98.424 ms35 MB + 388 KBAcceptedScore: 5

Testcase #10537.071 ms55 MB + 612 KBAcceptedScore: 5

Testcase #11541.964 ms55 MB + 616 KBAcceptedScore: 5

Testcase #12850.311 ms66 MB + 972 KBAcceptedScore: 5

Testcase #13849.353 ms66 MB + 976 KBAcceptedScore: 5

Testcase #14849.691 ms66 MB + 1000 KBAcceptedScore: 5

Testcase #1510.553 ms35 MB + 504 KBAcceptedScore: 5

Testcase #1610.557 ms35 MB + 508 KBAcceptedScore: 5

Testcase #17853.848 ms66 MB + 976 KBAcceptedScore: 5

Testcase #18854.3 ms66 MB + 976 KBAcceptedScore: 5

Testcase #191.347 s70 MB + 420 KBAcceptedScore: 5

Testcase #201.35 s70 MB + 440 KBAcceptedScore: 5


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