提交记录 4109


用户 题目 状态 得分 用时 内存 语言 代码长度
Dof noi18a. 【NOI2018】归程 Accepted 100 1.489 s 79720 KB C++ 2.52 KB
提交时间 评测时间
2018-07-18 20:58:45 2020-07-31 22:28:33
#include <cstdio>
#include <queue>
#include <cstring>
#include <algorithm>

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

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(gr, 0, sizeof gr);
	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);
			if (x == y) continue;
			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 #17.796 ms50 MB + 408 KBAcceptedScore: 5

Testcase #27.839 ms50 MB + 424 KBAcceptedScore: 5

Testcase #37.957 ms50 MB + 436 KBAcceptedScore: 5

Testcase #48.1 ms50 MB + 436 KBAcceptedScore: 5

Testcase #511.314 ms50 MB + 660 KBAcceptedScore: 5

Testcase #6710.585 ms74 MB + 52 KBAcceptedScore: 5

Testcase #710.443 ms50 MB + 556 KBAcceptedScore: 5

Testcase #810.502 ms50 MB + 560 KBAcceptedScore: 5

Testcase #910.44 ms50 MB + 556 KBAcceptedScore: 5

Testcase #10531.006 ms65 MB + 932 KBAcceptedScore: 5

Testcase #11532.4 ms65 MB + 936 KBAcceptedScore: 5

Testcase #12740.52 ms74 MB + 868 KBAcceptedScore: 5

Testcase #13740.009 ms74 MB + 780 KBAcceptedScore: 5

Testcase #14739.431 ms74 MB + 212 KBAcceptedScore: 5

Testcase #1511.851 ms50 MB + 664 KBAcceptedScore: 5

Testcase #1611.839 ms50 MB + 668 KBAcceptedScore: 5

Testcase #17740.766 ms74 MB + 428 KBAcceptedScore: 5

Testcase #18739.723 ms74 MB + 720 KBAcceptedScore: 5

Testcase #191.489 s77 MB + 872 KBAcceptedScore: 5

Testcase #201.489 s77 MB + 364 KBAcceptedScore: 5


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