QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#572188#5081. Forbidden Turnsdaxinghao#WA 3ms16236kbC++141.7kb2024-09-18 12:50:272024-09-18 12:50:30

Judging History

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

  • [2024-09-18 12:50:30]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:16236kb
  • [2024-09-18 12:50:27]
  • 提交

answer

#include <iostream>
#include <vector>
#include <map>
#include <queue>
#define int long long
using namespace std;
const int inf = 1e18;

int cost[300005];
int dis[300005];

vector<int> in[30005], out[30005];
vector<pair<int, int> > adj[300005];

signed main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int m, n, k; cin >> m >> n >> k;
    int a, b; cin >> a >> b;
    map<pair<int, int>, int> re;
    for (int i = 0; i < m; i++) {
        int u, v; cin >> u >> v >> cost[i];
        in[v].push_back(i);
        out[u].push_back(i);
        re[make_pair(u, v)] = i;
    }
    map<pair<int, int>, int> mp;
    for (int i = 0; i < k; i++) {
        int u, v, w; cin >> u >> v >> w;
        mp[make_pair(re[make_pair(u, v)], re[make_pair(v, w)])] = 1; 
    }
    for (int i = 0; i < n; i++) {
        for (int j: in[i]) {
            for (int k: out[i]) {
                if (!mp[make_pair(j, k)]) adj[j].push_back(make_pair(cost[k], k));
            }
        }
    }
    fill(dis, dis + 300005, inf);
    priority_queue<pair<int, int> > pq;
    for (int i: out[a]) {
        dis[i] = cost[i];
        pq.push(make_pair(-dis[i], i));
    }
    while (!pq.empty()) {
        int cur = pq.top().second;
        int dst = -pq.top().first;
        pq.pop();
        for (pair<int, int> p: adj[cur]) {
            if (dis[p.second] > dst + p.first) {
                dis[p.second] = dst + p.first;
                pq.push(make_pair(-dis[p.second], p.second));
            }
        }
    }
    int ans = inf;
    for (int i: in[b]) {
        ans = min(ans, dis[i]);
    }
    cout << (ans == inf ? -1 : ans) << '\n';
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 3ms
memory: 14560kb

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

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

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: 3ms
memory: 15204kb

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: 3ms
memory: 16236kb

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

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

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

input:

0 1 0
0 0

output:

-1

result:

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