提交记录 27721


用户 题目 状态 得分 用时 内存 语言 代码长度
D0000 noi18a. 【NOI2018】归程 Accepted 100 2.123 s 84096 KB C++17 2.18 KB
提交时间 评测时间
2025-01-13 17:38:47 2025-01-13 17:39:10
#include<cstdio>
#include<vector>
#include<queue>
#include<algorithm>
int n,m,cnt,q,k,s,t;
long long lastans;
struct edge2{
	int v,w;
};
struct node{
	bool b;
	std::vector<edge2>v;
}a[200005];
struct node2{
	int p,pp,zis;
    long long dis,xxx;
    int f[25];
}aa[400005];
struct edge{
	int u,v,w;
}e[400005];
struct eeee{
	int id;
    long long dis;
	bool operator >(const eeee& zyh)const{
		return dis>zyh.dis;
	}
};
std::priority_queue<eeee,std::vector<eeee>,std::greater<eeee> >pq;
void ddd(){
	while(pq.size())pq.pop();
	pq.push({1,0});
	aa[1].dis=0;
	for(int i=2;i<=n;i++)aa[i].dis=1e9;
	while(pq.size()){
		int now=pq.top().id;pq.pop();
		if(a[now].b)continue;
		a[now].b=1;
		for(edge2 v:a[now].v)if(aa[v.v].dis>aa[now].dis+v.w){
			aa[v.v].dis=aa[now].dis+v.w;
			pq.push({v.v,aa[v.v].dis});
		}
	}
}
bool cmp(edge a,edge b){
	return a.w>b.w;
}
int qu(int now){
    if(aa[now].pp==now)return now;
    aa[now].pp=qu(aa[now].pp);
    return aa[now].pp;
}
int main(){
//	freopen("return4.in","r",stdin);
//	freopen("out.txt","w",stdout);
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&m);
		for(int i=1;i<=n;i++) a[i].v.clear(),a[i].b=0;
		for(int i=1;i<=m;i++){
			int u,v,l,aaa;
			scanf("%d%d%d%d",&u,&v,&l,&aaa);
			e[i]={u,v,aaa};
			a[u].v.push_back({v,l});
			a[v].v.push_back({u,l});
		}
		ddd();
		std::sort(e+1,e+m+1,cmp);
    	for(int i=1;i<=n;i++)aa[i].p=aa[i].pp=i,aa[i].xxx=aa[i].dis,aa[i].zis=0;
    	cnt=n;
		for(int i=1;i<=m;i++){
			int pa=qu(e[i].u),pb=qu(e[i].v);
    	    if(pa==pb)continue;++cnt;
    	    aa[pa].p=aa[pa].pp=aa[pb].p=aa[pb].pp=aa[cnt].p=aa[cnt].pp=cnt;
    	    aa[cnt].xxx=std::min(aa[pb].xxx,aa[pa].xxx);
    	    aa[cnt].zis=e[i].w;//printf("(%d,%d,%d %d)",cnt,pa,pb,aa[cnt].zis);
		}
    	scanf("%d%d%d",&q,&k,&s);
    	for(int now=cnt;now;now--){
    		aa[now].f[0]=aa[now].p;
    		for(int i=1;i<25;i++)aa[now].f[i]=aa[aa[now].f[i-1]].f[i-1];
		}
		lastans=0;
    	while(q--){
    	    int v0,p0;
    	    scanf("%d%d",&v0,&p0);
    	    v0=((v0+k*lastans-1)%n)+1;
    	    p0=(p0+k*lastans)%(s+1);//printf("%d ",p0);
    	    for(int i=24;~i;i--)if(aa[aa[v0].f[i]].zis>p0&&aa[v0].f[i])v0=aa[v0].f[i];
    	    lastans=aa[v0].xxx;
    	    printf("%lld\n",lastans);
    	}
	}
	
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1815.68 us6 MB + 136 KBAcceptedScore: 5

Testcase #2839.8 us6 MB + 140 KBAcceptedScore: 5

Testcase #31.027 ms6 MB + 160 KBAcceptedScore: 5

Testcase #41.246 ms6 MB + 180 KBAcceptedScore: 5

Testcase #56.533 ms6 MB + 740 KBAcceptedScore: 5

Testcase #61.355 s78 MB + 352 KBAcceptedScore: 5

Testcase #75.216 ms6 MB + 636 KBAcceptedScore: 5

Testcase #85.294 ms6 MB + 640 KBAcceptedScore: 5

Testcase #95.185 ms6 MB + 636 KBAcceptedScore: 5

Testcase #10863.629 ms68 MB + 964 KBAcceptedScore: 5

Testcase #11863.505 ms68 MB + 968 KBAcceptedScore: 5

Testcase #121.382 s78 MB + 956 KBAcceptedScore: 5

Testcase #131.382 s78 MB + 872 KBAcceptedScore: 5

Testcase #141.382 s78 MB + 580 KBAcceptedScore: 5

Testcase #157.063 ms6 MB + 740 KBAcceptedScore: 5

Testcase #167.03 ms6 MB + 740 KBAcceptedScore: 5

Testcase #171.383 s78 MB + 704 KBAcceptedScore: 5

Testcase #181.382 s78 MB + 848 KBAcceptedScore: 5

Testcase #192.123 s82 MB + 128 KBAcceptedScore: 5

Testcase #202.123 s81 MB + 908 KBAcceptedScore: 5


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