提交记录 4232


用户 题目 状态 得分 用时 内存 语言 代码长度
Chuzyh noi18a. 【NOI2018】归程 Runtime Error 0 163.734 ms 93800 KB C++ 2.72 KB
提交时间 评测时间
2018-07-19 09:12:49 2020-07-31 22:44:35
#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
#include<algorithm>

using namespace std;

int n,m,T,q,x,y,z,zz,k,s,v0,p0,lastans,v,p,nowans;
const int N=1000000,INF=1e9;
int dis[N],vis[N],f[N],fa[N],ans[N],out[N],FA[N][20],H[N];
vector<int> son[N];
struct link
{
	int top,fi[N],ne[N],la[N],to[N],l[N],h[N];
	inline void clear()
	{
		top=0,memset(fi,0,sizeof fi),memset(ne,0,sizeof ne),memset(la,0,sizeof la),memset(to,0,sizeof to),memset(l,0,sizeof l),memset(h,0,sizeof h);
	}
	inline void add(int x,int y,int z,int H)
	{
		top++,to[top]=y,l[top]=z,h[top]=H;
		if(fi[x]==0)fi[x]=top;else ne[la[x]]=top;
		la[x]=top;
	}
}L;
struct node
{
	int id,dis;
	bool operator < (const node &a) const {return a.dis < dis;}
};
priority_queue<node> que;
inline void DIJKSTRA()
{
    for(int i=1;i<=n;i++)dis[i]=INF,vis[i]=0;
    dis[1]=0;while(!que.empty())que.pop();
    node tmp;
    tmp.id=1;tmp.dis=0;que.push(tmp);
    while (!que.empty()) 
	{
        int now=que.top().id;
        que.pop();
        if (vis[now]) continue;
        vis[now]=true;
        for (int i=L.fi[now];i;i=L.ne[i]) 
		{
            if (!vis[L.to[i]]&&dis[L.to[i]]>dis[now]+L.l[i]) 
			{
                dis[L.to[i]]=dis[now]+L.l[i];
                tmp.id=L.to[i];tmp.dis=dis[L.to[i]];
                que.push(tmp);
            }
        }
    }
}
struct E{int x,y,l,h;}e[N];
inline bool cmp(E a,E b){return a.h>b.h;}
inline int ASK(int x){if(fa[x]==x)return x;else return fa[x]=ASK(fa[x]);}
inline int Read()
{
    int x=0,f=1;char c=getchar();
    while(c>'9'||c<'0') {if(c=='-') f=-1;c=getchar();}
    while(c>='0'&&c<='9') {x=x*10+c-'0'; c=getchar();}
    return x*f;
}
void dfs(int x)
{
	for(int i=1;i<=19;i++)FA[x][i]=FA[FA[x][i-1]][i-1];
	for(int i=0;i<son[x].size();i++)
	{
		dfs(son[x][i]);
	}
}
int main()
{
	T=Read();
	while(T--)
	{
		L.clear();lastans=0;n=Read(),m=Read();
		for(int i=1;i<=2*n;i++)fa[i]=i;
		for(int i=1;i<=m;i++)
		{
			x=Read(),y=Read(),z=Read(),zz=Read();
			e[i].x=x,e[i].y=y,e[i].l=z,e[i].h=zz;
			L.add(x,y,z,zz),L.add(y,x,z,zz);
		}
		DIJKSTRA();sort(e+1,e+1+m,cmp);int tot=n;
		for(int i=1;i<=n;i++)ans[i]=dis[i],H[i]=1e9;
		q=Read(),k=Read(),s=Read();
		for(int i=1;i<=m;i++)
		{
			int fx=ASK(e[i].x),fy=ASK(e[i].y);
			if(fx!=fy)
			{
				tot++;fa[tot]=tot;fa[fx]=fa[fy]=tot;ans[tot]=min(ans[fx],ans[fy]);FA[fx][0]=FA[fy][0]=tot;
				H[tot]=e[i].h;
			}
		}
		int root;
		for(int i=1;i<=tot;i++)son[i].clear();
		for(int i=1;i<=tot;i++)
		{
			son[FA[i][0]].push_back(i);
			if(FA[i][0]==i)root=i;
		}
		dfs(root);
		while(q--)
		{
			scanf("%d%d",&v0,&p0);
			v=(v0+k*lastans-1)%n+1;
			p=(p0+k*lastans)%(s+1);
			int now=v;
			for(int i=19;i>=0;i--)if(H[FA[now][i]]>p)now=FA[now][i];
			lastans=ans[now];
			printf("%d\n",lastans);
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #15.153 ms45 MB + 840 KBRuntime ErrorScore: 0

Testcase #25.163 ms45 MB + 848 KBRuntime ErrorScore: 0

Testcase #35.176 ms45 MB + 856 KBRuntime ErrorScore: 0

Testcase #45.196 ms45 MB + 868 KBRuntime ErrorScore: 0

Testcase #55.892 ms46 MB + 188 KBRuntime ErrorScore: 0

Testcase #6138.658 ms80 MB + 616 KBRuntime ErrorScore: 0

Testcase #75.579 ms46 MB + 176 KBRuntime ErrorScore: 0

Testcase #85.49 ms46 MB + 176 KBRuntime ErrorScore: 0

Testcase #95.577 ms46 MB + 176 KBRuntime ErrorScore: 0

Testcase #1083.46 ms91 MB + 616 KBRuntime ErrorScore: 0

Testcase #1183.577 ms91 MB + 616 KBRuntime ErrorScore: 0

Testcase #12163.357 ms81 MB + 860 KBRuntime ErrorScore: 0

Testcase #13163.734 ms81 MB + 516 KBRuntime ErrorScore: 0

Testcase #14163.098 ms81 MB + 856 KBRuntime ErrorScore: 0

Testcase #156.069 ms46 MB + 196 KBRuntime ErrorScore: 0

Testcase #166.082 ms46 MB + 204 KBRuntime ErrorScore: 0

Testcase #17163.162 ms81 MB + 288 KBRuntime ErrorScore: 0

Testcase #18163.483 ms81 MB + 476 KBRuntime ErrorScore: 0

Testcase #19163.002 ms81 MB + 512 KBRuntime ErrorScore: 0

Testcase #20163.208 ms81 MB + 508 KBRuntime ErrorScore: 0


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