QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#870996#9345. Artful PaintingssluckystarWA 20ms3968kbC++141.6kb2025-01-25 19:02:312025-01-25 19:02:36

Judging History

你现在查看的是最新测评结果

  • [2025-01-25 19:02:36]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:3968kb
  • [2025-01-25 19:02:31]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;
const int N = 3000;
const int M = 3000;

int n, m1, m2, dis[N + 1], cnt[N + 1];
array<int, 3> p1[M + 1], p2[M + 1];
vector<pair<int, int>> edge[N + 1];
queue<int> que;
bool inq[N + 1];

bool SPFA() {
	for (int i = 1; i <= n; i++)
		dis[i] = 1 << 30, inq[i] = false;
	dis[0] = cnt[0] = 0;
	que.push(0), inq[0] = true;
	while (!que.empty()) {
		int node = que.front();
		que.pop(), inq[node] = false;
		for (auto i : edge[node])
			if (dis[i.first] > dis[node] + i.second) {
				dis[i.first] = dis[node] + i.second;
				cnt[i.first] = cnt[node] + 1;
				if (cnt[i.first] >= n + 1)
					return false;
				else if (!inq[i.first])
					que.push(i.first), inq[i.first] = true;
			}
	}
	return true;
}

bool judge(int num) {
	for (int i = 0; i <= n; i++)
		edge[i].clear();
	for (int i = 1; i <= m1; i++) {
		int u = p1[i][0], v = p1[i][1], w = p1[i][2];
		edge[v].push_back({u - 1, -w});
	}
	for (int i = 1; i <= m2; i++) {
		int u = p2[i][0], v = p2[i][1], w = p2[i][2];
		edge[u - 1].push_back({v, num - w});
	}
	for (int i = 1; i <= n; i++) {
		edge[i].push_back({i - 1, 0});
		edge[i - 1].push_back({i, 1});
	}
	return SPFA();
}

int main() {
	int test = 1;
	scanf("%d", &test);
	while (test--) {
		scanf("%d%d%d", &n, &m1, &m2);
		for (int i = 1; i <= m1; i++)
			for (int j = 0; j < 3; j++)
				scanf("%d", &p1[i][j]);
		for (int i = 1; i <= m2; i++)
			for (int j = 0; j < 3; j++)
				scanf("%d", &p2[i][j]);
		int l = 0, r = n + 1;
		while (l + 1 < r) {
			int mid = (l + r) / 2;
			if (!judge(mid))
				l = mid;
			else
				r = mid;
		}
		printf("%d\n", r);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3968kb

input:

1
3 1 1
1 2 1
2 2 1

output:

1

result:

ok single line: '1'

Test #2:

score: -100
Wrong Answer
time: 20ms
memory: 3968kb

input:

1
1000 500 500
479 860 170
73 939 25
363 772 30
185 584 89
326 482 10
784 949 23
384 740 114
233 693 45
167 724 211
217 436 95
46 701 153
138 585 67
321 388 11
114 890 194
407 854 74
438 845 117
9 718 259
393 576 35
182 707 257
451 766 136
150 382 31
468 785 40
202 490 46
326 815 59
272 441 77
123 8...

output:

500

result:

wrong answer 1st lines differ - expected: '492', found: '500'