QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#268207#5081. Forbidden TurnsSTnofarjo#WA 1ms3500kbC++201.4kb2023-11-28 13:25:062023-11-28 13:25:07

Judging History

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

  • [2023-11-28 13:25:07]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3500kb
  • [2023-11-28 13:25:06]
  • 提交

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]);
		}
	}
	cout << ans << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3428kb

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: 1ms
memory: 3492kb

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: 3464kb

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: 3500kb

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: -100
Wrong Answer
time: 1ms
memory: 3404kb

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:

2000000000

result:

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