提交记录 3964


用户 题目 状态 得分 用时 内存 语言 代码长度
Dof noi18a. 【NOI2018】归程 Wrong Answer 80 2.273 s 74928 KB C++ 2.47 KB
提交时间 评测时间
2018-07-18 20:12:32 2020-07-31 22:09:33
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>

typedef long long LL;
const int N = 600005, INF = 2e9 + 7, LOG = 19;

int tc, n, m, Qi, k, s;
int dis[N], flg[N], val[N], mdi[N], gr[LOG][N];
std::priority_queue<std::pair<int, int> > Q;

inline void Read(int &x) {
	x = 0; static char c;
	for (c = getchar(); c < '0' || c > '9'; c = getchar());
	for (; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
}

struct Edge {
	int u, v, a;
	inline friend bool operator < (Edge a, Edge b) {
		return a.a > b.a;
	}
} e[N];

int yun, las[N], to[N << 1], pre[N << 1], wi[N << 1];
inline void Add(int a, int b, int c = 0) {
	to[++yun] = b; wi[yun] = c; pre[yun] = las[a]; las[a] = yun;
}
void Gragh_clear() {
	memset(las, 0, sizeof las);
	yun = 0;
}

namespace DSU {
	int fa[N];
	void Init() {
		for (int i = 1; i <= n + m; ++i) {
			fa[i] = i;
			if (i <= n) mdi[i] = dis[i], val[i] = -1;
		}
	}
	int Seek(int x) {
		return (x == fa[x])? (x) : (fa[x] = Seek(fa[x]));
	}
	void Merge(int x, int y) {
		fa[Seek(y)] = x;
	}
}

void Dij() {
	for (int i = 1; i <= n; ++i) {
		dis[i] = INF; flg[i] = 0;
	}
	dis[1] = 0;
	Q.push(std::make_pair(0, 1));
	for (; !Q.empty(); ) {
		int x = Q.top().second; Q.pop();
		if (flg[x]) continue;
		flg[x] = 1;
		for (int i = las[x]; i; i = pre[i]) {
			if (dis[to[i]] > dis[x] + wi[i]) {
				dis[to[i]] = dis[x] + wi[i];
				Q.push(std::make_pair(-dis[to[i]], to[i]));
			}
		}
	}
}

int main() {
	scanf("%d", &tc);
	for (; tc; --tc) {
		scanf("%d%d", &n, &m);
		Gragh_clear();
		for (int i = 1, x, y, a, l; i <= m; ++i) {
			//scanf("%d%d%d%d", &x, &y, &l, &a);
			Read(x); Read(y); Read(l); Read(a);
			Add(x, y, l); Add(y, x, l);
			e[i] = (Edge) { x, y, a };
		}
		Dij(); DSU::Init();
		
		std::sort(e + 1, e + 1 + m);
		for (int i = 1; i <= m; ++i) {
			int x = DSU::Seek(e[i].u), y = DSU::Seek(e[i].v);
			val[i + n] = e[i].a;
			mdi[i + n] = std::min(mdi[x], mdi[y]);
			DSU::Merge(i + n, x); DSU::Merge(i + n, y);
			gr[0][x] = gr[0][y] = i + n;
		}
		
		for (int i = 1; i < LOG; ++i) {
			for (int j = 1; j <= n + m; ++j) {
				if (gr[i - 1][j]) gr[i][j] = gr[i - 1][gr[i - 1][j]];
			}
		}
		
		scanf("%d%d%d", &Qi, &k, &s);
		for (int x, a, lans = 0; Qi; --Qi) {
			//scanf("%d%d", &x, &a);
			Read(x); Read(a);
			x = (x + (LL) k * lans - 1) % n + 1;
			a = (a + (LL) k * lans) % (s + 1);
			for (int i = LOG - 1; ~i; --i) {
				if (gr[i][x] && val[gr[i][x]] > a) x = gr[i][x];
			}
			printf("%d\n", mdi[x]);
			lans = mdi[x];
		}
	}
	
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1304.02 us2 MB + 344 KBAcceptedScore: 5

Testcase #2331.53 us2 MB + 376 KBAcceptedScore: 5

Testcase #3455.17 us2 MB + 400 KBAcceptedScore: 5

Testcase #4602.47 us2 MB + 404 KBAcceptedScore: 5

Testcase #53.998 ms2 MB + 892 KBAcceptedScore: 5

Testcase #6779.266 ms68 MB + 652 KBAcceptedScore: 5

Testcase #72.926 ms2 MB + 640 KBAcceptedScore: 5

Testcase #82.931 ms2 MB + 648 KBAcceptedScore: 5

Testcase #92.923 ms2 MB + 644 KBAcceptedScore: 5

Testcase #10518.936 ms41 MB + 532 KBWrong AnswerScore: 0

Testcase #11543.377 ms41 MB + 516 KBWrong AnswerScore: 0

Testcase #12973.988 ms70 MB + 244 KBAcceptedScore: 5

Testcase #13973.455 ms70 MB + 80 KBAcceptedScore: 5

Testcase #14971.226 ms69 MB + 512 KBAcceptedScore: 5

Testcase #154.708 ms2 MB + 896 KBWrong AnswerScore: 0

Testcase #164.707 ms2 MB + 900 KBWrong AnswerScore: 0

Testcase #17973.818 ms69 MB + 780 KBAcceptedScore: 5

Testcase #18972.365 ms70 MB + 44 KBAcceptedScore: 5

Testcase #192.273 s73 MB + 176 KBAcceptedScore: 5

Testcase #202.264 s72 MB + 700 KBAcceptedScore: 5


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