提交记录 3932


用户 题目 状态 得分 用时 内存 语言 代码长度
functionendless noi18a. 【NOI2018】归程 Time Limit Exceeded 65 4 s 70124 KB C++ 3.53 KB
提交时间 评测时间
2018-07-18 19:57:14 2020-07-31 22:04:23
#include<cstdio>
#include<cstring>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<vector>
#include<queue>
#include<bitset>
#include<stack>
#include<cassert>
#include<cctype>
#define F first
#define S second
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define mem(x,y) memset(x,y,sizeof x)
#define sqr(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef double db;
const int INF=2e9;
const db eps=1e-12;
template<typename T>
inline void read(T &x)
{
	x=0; int f=1; char ch=getchar();
	while( (ch<'0' || ch>'9') && ch!='-') ch=getchar(); if(ch=='-') {f=-1; ch=getchar();}
	while(ch>='0' && ch <='9') x=x*10+ch-'0',ch=getchar();
	x*=f;
}
//==========================head template==========================
const int N=200010,M=400010,QQ=400010;
int n,m,K,Q,S;
struct Edge {
	int x,y,len,h,id;
	inline void in() {
		read(x); read(y); read(len); read(h);
	}
	bool operator < (const Edge &a)const {
		return h>a.h;
	}
}e[M];
int head[N],nxt[M<<1],to[M<<1],co[M<<1],h[M<<1],lst=1;
inline void adde(int x,int y,int c,int lim) {
	nxt[++lst]=head[x]; to[lst]=y; co[lst]=c; h[lst]=lim; head[x]=lst;
}
inline void add(int x,int y,int c,int h) {
	adde(x,y,c,h); adde(y,x,c,h);
}
bool used[N];
int dis[N];
priority_queue<pii,vector<pii>,greater<pii> > pq;
inline void Dij() {
	mem(used,0); mem(dis,63); dis[1]=0; pq.push(mp(0,1));
	while(!pq.empty()) {
		int u=pq.top().S; pq.pop();
		if(used[u]) continue; used[u]=1;
		for(int i=head[u];i;i=nxt[i]) {
			int v=to[i];
			if(!used[v] && dis[v]>dis[u]+co[i]) {
				dis[v]=dis[u]+co[i];
				pq.push(mp(dis[v],v));
			}
		}
	}
}
int que[N],he=1,ta=0;
int fat[N];
int father(int x) {return x==fat[x] ? x : fat[x]=father(fat[x]);}
const int ALL=N<<2,lgA=ceil(log2(ALL));
int val[ALL],lim[ALL],fa[ALL],dep[ALL],anc[ALL][lgA+2],bel[ALL],ch[ALL][2],ind;
void dfs(int u) {
	// printf("%d %d %d\n",u,ch[u][0],ch[u][1]);
	for(int i=0;i<2;i++) {
		int v=ch[u][i];
		if(!v) return;
		dep[v]=dep[u]+1;
		dfs(v);
	}
}
inline void Init() {
	for(int j=1;j<=lgA;j++)
		for(int i=1;i<=ind;i++)
			anc[i][j]=anc[anc[i][j-1]][j-1];
}
inline void Build() {
	for(int i=1;i<=n;i++) {fat[i]=i; bel[i]=i; val[i]=dis[i]; lim[i]=INF;}
	sort(e+1,e+m+1);
	ind=n;
	for(int i=1;i<=m;i++) {
		int fx=father(e[i].x),fy=father(e[i].y);
		if(fx!=fy) {
			// puts("?");
			int bx=bel[fx],by=bel[fy];
			anc[bx][0]=anc[by][0]=fa[bx]=fa[by]=++ind;
			val[ind]=min(val[bx],val[by]);
			ch[ind][0]=bx; ch[ind][1]=by;
			bel[fy]=ind; fat[fx]=fy;
			lim[ind]=e[i].h;
		}
	}
	// for(int i=1;i<=ind;i++) printf("u%d %d\n",ch[][])
	dep[ind]=1; dfs(ind); Init();
}
inline int Work(int u,int l) {
	// printf("%d %d\n",u,l);
	// for(int i=1;i<=ind;i++) printf("%d ",val[i]); puts("");
	// printf("%d %d\n",anc[u][0],anc[u][1]);
	for(int i=lgA;i>=0;i--) if(lim[anc[u][i]]>l) {u=anc[u][i];}
	return val[u];
}
signed main()
{
	// freopen("return5.in","r",stdin);
	// freopen("my.out","w",stdout);
	int T; read(T);
	int lans=0;
	while(T--) {
		lans=0;
		read(n); read(m); lst=1; mem(head,0);
		for(int i=1;i<=m;i++) {
			e[i].in();
			add(e[i].x,e[i].y,e[i].len,e[i].h);
			e[i].id=i;
		}
		Dij();
		// for(int i=1;i<=n;i++) printf("%d ",dis[i]); puts("");
		Build();
		read(Q); read(K); read(S);
		for(int i=1;i<=Q;i++) {
			int v,p; read(v); read(p);
			v=(v+1ll*K*lans-1)%n+1;
			p=(p+1ll*K*lans)%(S+1);
			// printf("%d %d\n",v,p);
			lans=Work(v,p);
			if(lans==INF) lans=0;
			printf("%d\n",lans);
		}
	}
	return 0;
}
/*
2
5 5
1 2 1 2
2 3 1 2
4 3 1 2
5 3 1 2
1 5 2 1
4 1 3
5 1
5 2
2 0
4 0
5 5
1 2 1 2
2 3 1 2
4 3 1 2
5 3 1 2
1 5 2 1
4 1 3
5 1
5 2
2 0
4 0
*/

CompilationN/AN/ACompile OKScore: N/A

Testcase #1227.58 us1 MB + 788 KBAcceptedScore: 5

Testcase #2250.11 us1 MB + 808 KBAcceptedScore: 5

Testcase #3367.62 us1 MB + 824 KBAcceptedScore: 5

Testcase #4528.07 us1 MB + 840 KBAcceptedScore: 5

Testcase #53.933 ms2 MB + 360 KBAcceptedScore: 5

Testcase #6678.538 ms66 MB + 956 KBAcceptedScore: 5

Testcase #73.175 ms2 MB + 228 KBAcceptedScore: 5

Testcase #83.18 ms2 MB + 232 KBAcceptedScore: 5

Testcase #93.175 ms2 MB + 228 KBAcceptedScore: 5

Testcase #10540.628 ms57 MB + 676 KBAcceptedScore: 5

Testcase #11541.084 ms57 MB + 684 KBAcceptedScore: 5

Testcase #124 s67 MB + 340 KBTime Limit ExceededScore: 0

Testcase #134 s67 MB + 320 KBTime Limit ExceededScore: 0

Testcase #144 s67 MB + 344 KBTime Limit ExceededScore: 0

Testcase #154.501 ms2 MB + 364 KBAcceptedScore: 5

Testcase #164.492 ms2 MB + 364 KBAcceptedScore: 5

Testcase #174 s67 MB + 384 KBTime Limit ExceededScore: 0

Testcase #184 s67 MB + 432 KBTime Limit ExceededScore: 0

Testcase #194 s68 MB + 376 KBTime Limit ExceededScore: 0

Testcase #204 s68 MB + 492 KBTime Limit ExceededScore: 0


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