QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#750076#9431. The Quest for El DoradoYuuWA 184ms9148kbC++233.3kb2024-11-15 12:32:422024-11-15 12:32:44

Judging History

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

  • [2024-11-15 12:32:44]
  • 评测
  • 测评结果:WA
  • 用时:184ms
  • 内存:9148kb
  • [2024-11-15 12:32:42]
  • 提交

answer

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

void sol(){
    int n, m, k;
    std::cin>>n>>m>>k;

    std::vector<std::map<int, std::set<std::array<int, 2>>>>G(n + 1);
    for(int i = 1;i <= m;i++){
        int u, v, c, cost;
        std::cin>>u>>v>>c>>cost;
        G[u][c].insert({cost, v});
        G[v][c].insert({cost, u});
    }

    auto del = [&](int u, int v,int c, int cost){
        G[u][c].erase({cost, c});
        if(G[u][c].size() == 0){
            G[u].erase(c);
        }
    };

    std::vector<std::map<int, std::set<int>>>SG(m + 1);
    {
        //  初始化边集
        std::vector<std::array<int, 4>>dell;
        for(auto& [c, E] : G[1]){
            for(auto& [cost, v] : E){
                SG[c][cost].insert(v);
                dell.push_back({1, v, c, cost});
            }
        }  

        for(auto [u, v, c, cost] : dell){
            del(u, v, c, cost);
            del(v, u, c, cost);
        }
    }

    const int inf = 2E18;
    std::vector<int>vis(n + 1);
    std::vector<int>dis(n + 1, inf);
    dis[1] = 0;
    vis[1] = 1;

    auto calc = [&](int c, int U){
        if(SG[c].size() == 0) return ;
        std::priority_queue<std::array<int, 2>, std::vector<std::array<int, 2>>, std::greater<>>Q;
        std::set<int>nw;
        std::vector<std::array<int, 2>>dl;
        for(auto& [cost, V] : SG[c]){
            if(cost > U) break;
            for(auto v : V){
                dl.push_back({cost, v});
                if(vis[v] == 0){
                    if(dis[v] > cost){
                        Q.push({dis[v] = cost, v});
                        nw.insert(v);
                    }
                }
            }
        }

        for(auto [cost, u] : dl){
            SG[c][cost].erase(u);
            if(SG[c][cost].size() == 0){
                SG[c].erase(cost);
            }
        }

        while(Q.size()){
            auto [d, u] = Q.top();
            Q.pop();
            
            if(dis[u] < d || G[u].count(c) == 0){
                continue ;
            }

            auto& E = G[u][c];
            for(auto [cost, v] : E){
                if(cost + d > U) break;
                if(vis[v] == 0 && dis[v] > cost + d){
                    Q.push({dis[v] = cost + d, v});
                    nw.insert(v);
                }
            }
        }

        //  加入新的点, 删除外点与内部点的边
        std::vector<std::array<int, 4>>dell;
        for(auto u : nw){
            vis[u] = 1;
        }
        for(auto u : nw){
            for(auto& [c, E] : G[u]){
                for(auto& [cost, v] : E){
                    if(vis[v] == 0){
                        dell.push_back({u, v, c, cost});
                        SG[c][cost].insert(v);
                    }
                }
            }
        }

        for(auto [u, v, c, cost] : dell){
            del(u, v, c, cost);
            del(v, u, c, cost);
        }
    };

    for(int i = 1;i <= k;i++){
        int c, U;
        std::cin>>c>>U;
        calc(c, U);
    }

    for(int i = 1;i <= n;i++){
        std::cout<<vis[i];
    }
    std::cout<<"\n";
}

signed main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1; std::cin>>t;
    while(t--) sol();  
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
5 6 4
1 2 1 30
2 3 1 50
2 5 5 50
3 4 6 10
2 4 5 30
2 5 1 40
1 70
6 100
5 40
1 30
3 1 1
2 3 1 10
1 100

output:

11011
100

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 184ms
memory: 9148kb

input:

1110
46 80 30
44 23 5 46
10 28 1 64
32 34 3 40
9 36 1 26
15 14 5 95
38 19 2 34
2 17 4 183
10 38 2 81
5 15 2 83
31 38 3 100
40 30 1 53
41 10 1 193
29 20 5 18
14 41 3 78
8 16 5 74
46 13 3 78
44 28 3 45
1 40 3 133
5 32 1 108
22 26 2 83
10 38 1 77
11 40 1 11
17 21 2 66
41 46 3 98
9 36 2 25
40 18 1 19
27...

output:

1000110011110111110010100001010100100101000000
1100010010111011011011000000011000001100001000
1000000000000000000000000000000000000000000000
1011010000000010000100010011000100000000000010
1000000000000000000000101000010000001001000001
1001100010110000100001100000000011001110110
101010000000000000010...

result:

wrong answer 810th lines differ - expected: '11100010010010110100000000010111101011110000100111', found: '11000010000000010100000000000000100001010000100000'