QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#420941#6523. Escape PlanElbertWA 1ms3580kbC++143.3kb2024-05-25 05:16:582024-05-25 05:16:59

Judging History

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

  • [2024-05-25 05:16:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3580kb
  • [2024-05-25 05:16:58]
  • 提交

answer

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
#define V vector
typedef vector<int> vi;

struct Node{
    int time;
    int to;
    int from;
    int w;
};


int main() {
    int T;
    cin>>T;
    while(T--){
        cin.tie(0)->sync_with_stdio(0);
        cin.exceptions(cin.failbit);

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

        auto cmp = [](Node& l, Node& r){ return l.time < r.time;};
        priority_queue<Node, V<Node>, decltype(cmp)> q(cmp);

        rep(i,0,k) {
            int idx;
            cin>>idx;
            q.push({0,idx,0,0});
        }

        vi mons(n+1);
        rep(i,1,n+1){
            cin>>mons[i];
        }

        V<V<set<int>>> g(n+1, V<set<int>>(n+1));
        rep(i,0,m){
            int x,y,w;
            cin>>x>>y>>w;

            g[x][y].insert(w);
            g[y][x].insert(w);
        }

        // actual traverse
        while (!q.empty()){
            Node cur = q.top();
            q.pop();

            //cout<<"Visiting: "<<cur.to<<endl;

            // can we be blocked?
            if(cur.from && mons[cur.to]) {
                // dedicate the monster
                mons[cur.to]--;
                // remove the path from being possible
                g[cur.from][cur.to].erase(cur.w);
                g[cur.to][cur.from].erase(cur.w);
                continue;
            }

            // we can make it! Update time
            cur.time += cur.w;

            // got to monster hunter!
            if(cur.to == 1){
                cout<<cur.time<<endl;
                return 0;
            }

            // prop to other spots
            rep(i,0,g[cur.to].size()){
                for(int w : g[cur.to][i]){
                    q.push({cur.time, i, cur.to, w});
                }
            }
        }
        cout<<-1<<endl;
        return 0;
    }
}

// struct Edge{
//     int x,y,w;
// };
    // // V<vi> g(n+1, vi(n+1,0));
    // V<V<Edge*>> g(n+1);
    // Edge e[m];
    // rep(i,0,m){
    //     cin>>e[i].x>>e[i].y>>e[i].w;

    //     g[e[i].x].push_back(e+i);
    //     g[e[i].y].push_back(e+i);
    //     // g[x][y] = w;
    //     // g[y][x] = w;
    // }

    // // actual traverse
    // while (!q.empty()){
    //     Node cur = q.top();
    //     q.pop();

    //     // got to monster hunter!
    //     if(cur.idx == 1){
    //         cout<<cur.time<<endl;
    //         return 0;
    //     }

    //     cout<<"Visiting: "<<cur.idx<<endl;

    //     // prop to other spots
    //     rep(i,0,g[cur.idx].size()){
    //         Edge* ed = g[cur.idx][i];
    //     // for(Edge* ed : g[cur.idx]){
    //         // can we go to i?
    //         // if(g[cur.idx][p.first].second){
    //             // can a monster block?
    //         int to = ed->x;
    //         int from = ed->y;
    //         if(to == cur.idx) swap(to,from);

    //         if(mons[to]){
    //             mons[to]--;

    //             g[to].erase(&ed);
    //             g[from].erase(&ed);
    //             // g[to].erase(g[to].find(ed));
    //             // g[from].erase(g[from].find(ed));
    //         } else {
    //             // go to the spot!
    //             q.push({ed->w+cur.time, to});
    //         }
    //     }
    // }


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3580kb

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

result:

wrong answer Answer contains longer sequence [length = 2], but output contains 1 elements