提交记录 3703


用户 题目 状态 得分 用时 内存 语言 代码长度
Imagine noi18a. 【NOI2018】归程 Accepted 100 1.456 s 254124 KB C++ 2.69 KB
提交时间 评测时间
2018-07-18 14:15:17 2020-07-31 21:22:52
#include<queue>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 6e5 + 10;

struct E {
	int u, v, l, a;
	bool operator < (const E& A) const { return a > A.a; }
} e[maxn];

struct Edge {
	Edge* next;
	int to, w;
	Edge(Edge* next = 0, int to = 0, int w = 0): next(next), to(to), w(w) {}
} *first[maxn], *f2[maxn];

int n, m, f[maxn], d[maxn], vis[maxn], de[maxn], c, q, k, s, vi[maxn][20], pi[maxn][20];

int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }

struct Node {
	int u, w;
	Node(int u = 0, int w = 0): u(u), w(w) {}
	bool operator < (const Node& A) const { return w > A.w; }
};

void Dijkstra() {
	priority_queue<Node> Q; Q.push(Node(1, 0));
	memset(d, 0x3f, sizeof d), d[1] = 0;
	memset(vis, 0, sizeof vis);
	while (!Q.empty()) {
		Node x = Q.top(); Q.pop();
		if (vis[x.u]) continue;
		vis[x.u] = 1;
		for (Edge* now = first[x.u]; now; now = now->next) {
			if (d[now->to] > d[x.u] + now->w) {
				d[now->to] = d[x.u] + now->w;
				Q.push(Node(now->to, d[now->to]));
			}
		}
	}
}

void Add(int u, int v, int w) {
	f2[u] = new Edge(f2[u], v, w);
	f2[v] = new Edge(f2[v], u, w);
}

void Dfs(int u, int pa) {
	for (int i = 1; (1 << i) <= c; i++) pi[u][i] = pi[pi[u][i - 1]][i - 1];
	for (int i = 1; (1 << i) <= c; i++) vi[u][i] = min(vi[u][i - 1], vi[pi[u][i - 1]][i - 1]);
	for (Edge* now = f2[u]; now; now = now->next) {
		if (now->to == pa) continue;
		pi[now->to][0] = u, vi[now->to][0] = now->w;
		de[now->to] = de[u] + 1, Dfs(now->to, u);
		d[u] = min(d[u], d[now->to]);
	}
}

inline int read() {
	int x = 0;
	char ch = getchar();
	for (; !isdigit(ch); ch = getchar());
	for (; isdigit(ch); ch = getchar()) x = (x << 3) + (x << 1) + ch - 48;
	return x;
}

int main() {
	int T; scanf("%d", &T);
	while (T--) {
		memset(first, 0, sizeof first);
		memset(f2, 0, sizeof f2);
		scanf("%d%d", &n, &m);
		for (int i = 1; i <= m; i++) {
			e[i].u = read(), e[i].v = read(), e[i].l = read(), e[i].a = read();
			first[e[i].u] = new Edge(first[e[i].u], e[i].v, e[i].l);
			first[e[i].v] = new Edge(first[e[i].v], e[i].u, e[i].l);
		}
		Dijkstra();
		sort(e + 1, e + 1 + m);
		for (int i = 1; i <= n << 1; i++) f[i] = i;
		c = n;
		for (int i = 1; i <= m; i++) {
			int u = find(e[i].u), v = find(e[i].v);
			if (u == v) continue;
			Add(++c, u, e[i].a), Add(c, v, e[i].a);
			f[u] = f[v] = c;
		}
		memset(pi, 0, sizeof pi);
		de[c] = 1, Dfs(c, 0);
		int ans = 0;
		scanf("%d%d%d", &q, &k, &s);
		while (q--) {
			int v = read(), p = read();
			v = (v + 1ll * k * ans - 1) % n + 1;
			p = (p + 1ll * k * ans) % (s + 1);
			for (int i = 19; ~i; i--) {
				if (de[v] - (1 << i) > 0 && vi[v][i] > p) {
					v = pi[v][i];
				}
			}
			printf("%d\n", ans = d[v]);
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #19.223 ms59 MB + 556 KBAcceptedScore: 5

Testcase #29.264 ms59 MB + 568 KBAcceptedScore: 5

Testcase #39.403 ms59 MB + 612 KBAcceptedScore: 5

Testcase #49.537 ms59 MB + 660 KBAcceptedScore: 5

Testcase #513.47 ms61 MB + 36 KBAcceptedScore: 5

Testcase #6787.656 ms240 MB + 224 KBAcceptedScore: 5

Testcase #712.717 ms60 MB + 728 KBAcceptedScore: 5

Testcase #812.702 ms60 MB + 736 KBAcceptedScore: 5

Testcase #912.713 ms60 MB + 732 KBAcceptedScore: 5

Testcase #10696.483 ms210 MB + 412 KBAcceptedScore: 5

Testcase #11699.077 ms210 MB + 420 KBAcceptedScore: 5

Testcase #12896.289 ms244 MB + 704 KBAcceptedScore: 5

Testcase #13896.173 ms244 MB + 708 KBAcceptedScore: 5

Testcase #14895.894 ms244 MB + 728 KBAcceptedScore: 5

Testcase #1513.963 ms61 MB + 60 KBAcceptedScore: 5

Testcase #1613.963 ms61 MB + 64 KBAcceptedScore: 5

Testcase #17896.55 ms244 MB + 708 KBAcceptedScore: 5

Testcase #18895.587 ms244 MB + 704 KBAcceptedScore: 5

Testcase #191.45 s248 MB + 152 KBAcceptedScore: 5

Testcase #201.456 s248 MB + 172 KBAcceptedScore: 5


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