提交记录 3734


用户 题目 状态 得分 用时 内存 语言 代码长度
jokerwyt noi18a. 【NOI2018】归程 Wrong Answer 65 1.078 s 39768 KB C++ 2.02 KB
提交时间 评测时间
2018-07-18 16:02:07 2020-07-31 21:25:41
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
using namespace std;
const int N = 4e5 + 10, M = 8e5 + 10; //开大!!! 
int T;
int n,m,final[N],nex[M];
struct edge{
	int x,y,len,hi;
	bool operator < (const edge & e) const {
		return hi < e.hi || hi == e.hi && len > e.len;
	}
} e[M], es[M];

char c;
void read(int &x) {
	while ((c=getchar()) > '9' || c < '0');
	x = c - '0';
	while ((c=getchar()) >= '0' && c <= '9') x = x * 10 + c - '0';
}

int lastans;
int dis[N];
set<pair<int,int> > he;

void dij() {
	memset(dis, 127, sizeof dis); dis[1] = 0;
	he.clear();
	he.insert(make_pair(0, 1));
	while (!he.empty()) {
		int x = (*he.begin()).second;
		he.erase(he.begin());
		for (int i = final[x]; i; i=nex[i]) {
			int y = e[i].y;
			if (dis[x] + e[i].len < dis[y]) {
				if (dis[y] != dis[0]) he.erase(make_pair(dis[y], y));
				dis[y] = dis[x] + e[i].len;
				he.insert(make_pair(dis[y], y));
			}
		}
	}
}

int Q,K,S;
int ans[N],mi[N],fa[N];

int gf(int x) {
	return fa[x] == 0 ? x : fa[x] = gf(fa[x]);
}

void merge(int x,int y) {
	x = gf(x), y = gf(y);
	if (x != y) {
		fa[x] = y;
		mi[y] = min(mi[y], mi[x]);
	}
}

int main() { 
	for (cin>>T; T; T--) {
		memset(final,0,sizeof final);
		memset(e,0,sizeof e);
		memset(nex,0,sizeof nex);
		cin>>n>>m;
		for (int i = 1; i <= m; i++) {
			read(e[i].x),read(e[i].y),read(e[i].len),read(e[i].hi);
			es[i] = e[i + m] = e[i];
			swap(e[i + m].x, e[i + m].y);
		}
		sort(e + 1, e + 1 + m * 2);
		for (int i = 1; i <= m * 2; i++) {
			nex[i] = final[e[i].x];
			final[e[i].x] = i;
		}
		
		dij();
		memset(fa,0,sizeof fa);
		for (int i = 1; i <= n; i++) mi[i] = dis[i];
		
		cin>>Q>>K>>S;
		for (int z = 1; z <= Q; z++) {
			int v,p; read(v),read(p);
			es[m + z].x = v, es[m + z].y = z, es[m + z].hi = p;
			es[m + z].len = -1;
		}
		
		sort(es + 1,es + 1 + m + Q);
		for (int i = m + Q; i; i--) {
			if (es[i].len > 0) {
				merge(es[i].x,es[i].y);
			} else {
				ans[es[i].y] = mi[gf(es[i].x)];
			}
		}
		
		for (int i = 1; i <= Q; i++) {
			printf("%d\n",ans[i]);
		}
	}
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #13.123 ms19 MB + 892 KBAcceptedScore: 5

Testcase #23.161 ms19 MB + 900 KBAcceptedScore: 5

Testcase #33.307 ms19 MB + 908 KBAcceptedScore: 5

Testcase #43.463 ms19 MB + 912 KBAcceptedScore: 5

Testcase #57.563 ms20 MB + 16 KBAcceptedScore: 5

Testcase #6678.112 ms30 MB + 272 KBAcceptedScore: 5

Testcase #76.233 ms19 MB + 1008 KBAcceptedScore: 5

Testcase #86.242 ms19 MB + 1012 KBAcceptedScore: 5

Testcase #96.24 ms19 MB + 1008 KBAcceptedScore: 5

Testcase #10339.1 ms28 MB + 144 KBAcceptedScore: 5

Testcase #11332.164 ms28 MB + 184 KBWrong AnswerScore: 0

Testcase #12766.159 ms29 MB + 868 KBAcceptedScore: 5

Testcase #13763.584 ms29 MB + 864 KBAcceptedScore: 5

Testcase #14767.707 ms29 MB + 872 KBAcceptedScore: 5

Testcase #158.617 ms20 MB + 8 KBWrong AnswerScore: 0

Testcase #168.628 ms20 MB + 8 KBWrong AnswerScore: 0

Testcase #17764.398 ms29 MB + 820 KBWrong AnswerScore: 0

Testcase #18765.658 ms29 MB + 820 KBWrong AnswerScore: 0

Testcase #191.078 s38 MB + 836 KBWrong AnswerScore: 0

Testcase #201.077 s38 MB + 856 KBWrong AnswerScore: 0


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