提交记录 18579


用户 题目 状态 得分 用时 内存 语言 代码长度
huaruoji noi18a. 【NOI2018】归程 Accepted 100 1.105 s 99700 KB C++11 3.26 KB
提交时间 评测时间
2022-10-26 17:35:26 2022-10-26 17:35:37
#include <bits/stdc++.h>

using namespace std;
namespace DEBUG {
	void debug_out() { cerr << '\n'; }
	template <typename Head, typename... Tail>
	void debug_out(Head H, Tail... T) { cerr << ' ' << H, debug_out(T...); }
	#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
} using namespace DEBUG;
namespace fastIO {
	char B[1 << 16], *S = B, *T = B;
	inline char getchar() { return S == T && (T = (S = B) + fread(B, 1, 1 << 16, stdin), S == T) ? EOF : *S++; }
	template<typename Tp> inline void read(Tp &o) {
		o = 0; bool s = 0; char c = getchar();
		while(c > '9' || c < '0') s |= c == '-', c = getchar();
		while(c >= '0' && c <= '9') o = o * 10 + c - '0', c = getchar();
		if(s) o = -o;
	}
} using fastIO::read;
template<typename T> inline void cmin(T &a, T b) { if(a > b) a = b; }
typedef long long ll;
#define eb emplace_back
#define all(x) x.begin(), x.end()
const int N = 2e5 + 5;
int T, n, m, Q, K, S;
struct edge {
	int u, v, l, a;
};
vector<edge> g[N];
vector<edge> edges;
int dis[N], vis[N];
struct node {
	int dis, id;
	bool operator<(const node &x) const {
		return dis > x.dis;
	}
};
priority_queue<node> q;
// disµÃ·À±¬£¡ 
void dijkstra() {
	for(int i = 1; i <= n; i++) dis[i] = 2e9, vis[i] = false;
	dis[1] = 0, q.push(node{0, 1});
	while(!q.empty()) {
		int u = q.top().id;
//		debug(u);
		q.pop();
		if(vis[u]) continue;
		vis[u] = true;
		for(edge &e : g[u]) {
			int v = e.v, w = e.l;
			if(dis[v] > (ll)dis[u] + w) {
				dis[v] = dis[u] + w;
				if(!vis[v]) q.push(node{dis[v], v});
			}
		}
	}
//	for(int i = 1; i <= n; i++) debug(i, dis[i]);
}
// kruskalÖع¹Ê÷ Á½±¶½Úµã 
// DSU ²»ÄÜÆô·¢Ê½ºÏ²¢£¬ÒòΪÿ¸öµãµÄ¸¸Ç×±ØÐëÊÇËüÄǸö¶ÑµÄ¶¥ 
struct DSU {
	int fa[N * 2];
	int find(int x) {
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	DSU() {
		for(int i = 1; i <= 2 * n; i++) fa[i] = i;
	}
}; 
// Á½±¶½ÚµãºóµÄlog 
int cnt, val[N * 2], fa[N * 2][20], minv[N * 2];
vector<int> g2[N * 2];
void kruskal() {
	sort(all(edges), [&](const edge &a, const edge &b) {
		return a.a > b.a;
	});
	DSU S;
	cnt = n;
	for(edge &e : edges) {
		int x = S.find(e.u), y = S.find(e.v);
		if(x == y) continue;
		val[++cnt] = e.a;
		g2[cnt].eb(x), g2[cnt].eb(y);
		S.fa[x] = cnt, S.fa[y] = cnt;
		if(cnt == 2 * n - 1) break;
	}
}
void dfs(int u, int f) {
	minv[u] = (u <= n) ? dis[u] : 2e9;
	fa[u][0] = f;
	for(int i = 1; fa[u][i - 1]; i++)
		fa[u][i] = fa[fa[u][i - 1]][i - 1];
	for(int v : g2[u])
		dfs(v, u), cmin(minv[u], minv[v]);
}
int query(int v, int p) {
	int now = v;
	for(int i = 19; i >= 0; i--)
		if(fa[now][i] && val[fa[now][i]] > p) now = fa[now][i];
	return minv[now];
}
void clear() {
	for(int i = 1; i <= n; i++) g[i].clear();
	for(int i = 1; i <= 2 * n; i++) g2[i].clear();
	memset(fa, 0, sizeof fa);
	edges.clear();
}

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	for(read(T); T; T--) {
		// ¶à²âÇå¿Õ 
		read(n), read(m);
		clear();
		for(int i = 1, u, v, l, a; i <= m; i++) {
			read(u), read(v), read(l), read(a);
			g[u].eb(edge{u, v, l, a}), g[v].eb(edge{v, u, l, a});
			edges.eb(edge{u, v, l, a});
		}
		dijkstra();
		kruskal();
		dfs(cnt, 0);
		read(Q), read(K), read(S);
		int ans = 0;
		for(int i = 1, v, p; i <= Q; i++) {
			read(v), read(p);
			v = (v + K * ans - 1) % n + 1, p = (p + K * ans) % (S + 1);
			cout << (ans = query(v, p)) << '\n';
		}
	}

	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #17.253 ms45 MB + 872 KBAcceptedScore: 5

Testcase #27.343 ms45 MB + 880 KBAcceptedScore: 5

Testcase #37.426 ms45 MB + 896 KBAcceptedScore: 5

Testcase #47.451 ms45 MB + 920 KBAcceptedScore: 5

Testcase #59.918 ms46 MB + 292 KBAcceptedScore: 5

Testcase #6657.977 ms89 MB + 860 KBAcceptedScore: 5

Testcase #79.202 ms46 MB + 136 KBAcceptedScore: 5

Testcase #89.189 ms46 MB + 136 KBAcceptedScore: 5

Testcase #99.151 ms46 MB + 132 KBAcceptedScore: 5

Testcase #10518.384 ms71 MB + 368 KBAcceptedScore: 5

Testcase #11518.905 ms71 MB + 376 KBAcceptedScore: 5

Testcase #12718.207 ms93 MB + 908 KBAcceptedScore: 5

Testcase #13718.539 ms93 MB + 912 KBAcceptedScore: 5

Testcase #14718.568 ms93 MB + 932 KBAcceptedScore: 5

Testcase #1510.3 ms46 MB + 288 KBAcceptedScore: 5

Testcase #1610.252 ms46 MB + 296 KBAcceptedScore: 5

Testcase #17719.042 ms93 MB + 916 KBAcceptedScore: 5

Testcase #18719.172 ms93 MB + 908 KBAcceptedScore: 5

Testcase #191.1 s97 MB + 360 KBAcceptedScore: 5

Testcase #201.105 s97 MB + 372 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-04-23 20:10:34 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用