QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268210#5081. Forbidden TurnsSTnofarjo#WA 1ms3620kbC++201.5kb2023-11-28 13:27:142023-11-28 13:27:14

Judging History

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

  • [2023-11-28 13:27:14]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3620kb
  • [2023-11-28 13:27:14]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int INF = 2e9;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);

	int m, n, k, v, w;
	cin >> m >> n >> k;
	cin >> v >> w;

	vector<vector<pair<int, int>>> from(n);

	vector<pair<int, int>> edges(m);
	map<pair<int, int>, int> edge_idx;
	vector<int> dis(m, INF);
	for (int i = 0; i < m; i++) {
		int x, y, c;
		cin >> x >> y >> c;
		edges[i] = make_pair(x, y);
		from[x].emplace_back(y, c);
		edge_idx[make_pair(x, y)] = i;
	}

	set<int> forbid[m];
	for (int i = 0; i < k; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		forbid[edge_idx[make_pair(x, y)]].insert(edge_idx[make_pair(y, z)]);
	}

	set<pair<int, int>> Q;
	for (auto nx : from[v]) {
		int cur_id = edge_idx[make_pair(v, nx.first)];
		dis[cur_id] = nx.second;
		Q.emplace(dis[cur_id], cur_id);
	}

	while (!Q.empty()) {
		auto now = Q.begin();
		Q.erase(Q.begin());
		int cur_id = now->second;
		int v = edges[cur_id].second;
		for (auto c : from[v]) {
			int nx_edge_id = edge_idx[make_pair(v, c.first)];
			if (forbid[cur_id].count(nx_edge_id)) continue;
			if (dis[nx_edge_id] > dis[cur_id] + c.second) {
				Q.erase(make_pair(dis[nx_edge_id], nx_edge_id));
				dis[nx_edge_id] = dis[cur_id] + c.second;
				Q.emplace(dis[nx_edge_id], nx_edge_id);
			}
		}
	}

	int ans = INF;
	for (int i = 0; i < m; i++) {
		if (edges[i].second == w) {
			ans = min(ans, dis[i]);
		}
	}
	if (ans == INF) {
		cout << -1 << '\n';
		return 0;
	}
	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3528kb

input:

9 7 3
3 2
6 3 2
3 0 3
0 1 12
1 0 4
1 2 2
1 5 4
4 1 8
5 4 7
5 2 5
0 1 2
4 1 5
1 5 2

output:

36

result:

ok single line: '36'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3524kb

input:

4 4 1
0 3
0 1 2
1 2 3
0 2 7
2 3 10
0 1 2

output:

17

result:

ok single line: '17'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

4 4 0
0 3
0 1 2
1 2 3
0 2 7
2 3 10

output:

15

result:

ok single line: '15'

Test #4:

score: 0
Accepted
time: 0ms
memory: 3620kb

input:

4 4 1
1 0
1 2 3
2 3 10
3 2 12
2 0 7
1 2 0

output:

32

result:

ok single line: '32'

Test #5:

score: 0
Accepted
time: 0ms
memory: 3612kb

input:

13 8 5
0 5
0 2 3
2 1 7
4 2 10
2 3 10
3 2 12
2 5 10
3 6 10
6 7 5
7 3 5
6 4 10
4 1 0
1 4 10
4 6 10
0 2 1
0 2 5
3 2 5
2 3 2
6 4 2

output:

63

result:

ok single line: '63'

Test #6:

score: 0
Accepted
time: 0ms
memory: 3536kb

input:

4 4 2
1 0
1 2 3
2 3 10
3 2 12
2 0 7
1 2 0
2 3 2

output:

-1

result:

ok single line: '-1'

Test #7:

score: 0
Accepted
time: 0ms
memory: 3528kb

input:

4 4 0
1 0
1 2 3
2 3 2
3 2 3
2 0 7

output:

10

result:

ok single line: '10'

Test #8:

score: -100
Wrong Answer
time: 0ms
memory: 3588kb

input:

0 1 0
0 0

output:

-1

result:

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