QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#329571#6523. Escape Plantien_noobAC ✓823ms49372kbC++201.8kb2024-02-16 21:56:152024-02-16 21:56:15

Judging History

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

  • [2024-02-16 21:56:15]
  • 评测
  • 测评结果:AC
  • 用时:823ms
  • 内存:49372kb
  • [2024-02-16 21:56:15]
  • 提交

answer

//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 3e5, M = 1e6;
int x[M + 1], y[M + 1], w[M + 1];
vector<int> adj[N + 1];
int d[N + 1], dis[N + 1];
int n, m, k;
priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;
void read()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++ i)
    {
        adj[i].clear();
        dis[i] = -1;
    }
    for (int i = 1; i <= k; ++ i)
    {
        int u;
        cin >> u;
        dis[u] = 0;
        PQ.push({0, u});
    }
    for (int i = 1; i <= n; ++ i)
    {
        cin >> d[i];
    }
    for (int i = 1; i <= m; ++ i)
    {
        int u, v;
        cin >> u >> v >> w[i];
        x[i] = u;
        y[i] = v;
        adj[u].push_back(i);
        adj[v].push_back(i);
    }
}
void solve()
{
    while(!PQ.empty())
    {
        pair<int, int> p = PQ.top();
        PQ.pop();
        int cur_w = p.first, u = p.second;
        if (cur_w == 0)
        {
            d[u] = 0;
        }
        if (--d[u] == -1)
        {
            dis[u] = cur_w;
            for (int i : adj[u])
            {
                int v = x[i] ^ y[i] ^ u;
                PQ.push({dis[u] + w[i], v});
            }
        }
    }
    cout << dis[1] << '\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = true;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

详细

Test #1:

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

input:

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

output:

4
-1

result:

ok 2 number(s): "4 -1"

Test #2:

score: 0
Accepted
time: 823ms
memory: 49372kb

input:

100
100 1808 2
94 47
3 3 0 2 4 3 3 4 0 0 2 2 2 3 2 4 0 2 3 4 4 2 0 3 4 3 1 0 2 1 2 2 0 3 4 4 4 1 2 2 3 1 0 0 3 1 4 2 1 3 3 4 3 0 4 1 0 3 2 1 4 4 1 3 2 3 3 3 3 1 0 3 0 4 3 1 0 4 0 4 4 1 2 0 0 4 1 3 3 3 0 2 2 1 1 2 3 4 1 2
72 29 1138
59 78 2398
95 5 1610
32 46 4176
36 99 8143
100 69 413
61 58 1595
9 9...

output:

5109
1021
3293
4646
3796
3394
1884
6772
2329
2067
3296
2809
865
4249
2241
3792
2135
2544
3343
1775
10602
4677
1700
2150
7071
14055
3368
2322
1113
1980
3067
1617
1702
-1
2879
6265
2065
2810
2289
3001
402
3769
18118
6874
7879
3823
-1
510
2636
10564
-1
3166
3615
7526
5549
1261
3302
270
4440
1998
3350
3...

result:

ok 100 numbers