QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#784132#8874. Labelled PathsalexhamidiWA 1ms3616kbC++202.0kb2024-11-26 13:39:192024-11-26 13:39:23

Judging History

This is the latest submission verdict.

  • [2024-11-26 13:39:23]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3616kb
  • [2024-11-26 13:39:19]
  • Submitted

answer

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
using namespace std;

struct Edge {
    int v, p, l;
    string label;
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, m, d, s;
    cin >> n >> m >> d >> s;

    string A;
    cin >> A;

    vector<vector<Edge>> graph(n+1);
    for (int i = 0; i < m; i++) {
        int u, v, p, l;
        cin >> u >> v >> p >> l;
        graph[u].push_back({v, p-1, l, A.substr(p-1, l)});
    }

    auto findShortestPath = [&](int start, int end) {
        vector<vector<pair<string, vector<int>>>> dist(n+1);
        priority_queue<
            pair<pair<int, string>, vector<int>>, 
            vector<pair<pair<int, string>, vector<int>>>, 
            greater<pair<pair<int, string>, vector<int>>>
        > pq;

        pq.push({{0, ""}, {start}});

        while (!pq.empty()) {
            auto [info, path] = pq.top(); 
            pq.pop();
            int curr = path.back();
            
            if (curr == end) return path;
            
            for (auto& edge : graph[curr]) {
                vector<int> newPath = path;
                newPath.push_back(edge.v);
                string newStr = info.second + edge.label;
                
                if (dist[edge.v].empty() || 
                    make_pair(newPath.size(), newStr) < 
                    make_pair(dist[edge.v][0].second.size(), dist[edge.v][0].first)) {
                    dist[edge.v] = {{newStr, newPath}};
                    pq.push({{newPath.size(), newStr}, newPath});
                }
            }
        }
        
        return vector<int>();
    };

    for (int i = 1; i <= n; i++) {
        auto path = findShortestPath(s, i);
        
        if (path.empty()) {
            cout << "0\n";
        } else {
            cout << path.size() << " ";
            for (int node : path) cout << node << " ";
            cout << "\n";
        }
    }

    return 0;
}

详细

Test #1:

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

input:

11 30 105 9
fufuffuffuuuuuufuffuffuufffuufufuuuuuuuuuufffufufffuuufuffufufuuffffuufffuffffuffffufuuuufuufuuffuuuufffu
1 6 51 1
5 2 6 1
9 6 57 3
11 8 86 4
10 8 95 0
6 2 17 0
6 3 78 0
7 3 50 0
11 4 98 3
10 3 77 3
5 4 18 4
7 4 81 1
9 7 82 0
1 3 79 2
7 5 13 4
1 10 86 2
10 4 10 0
9 3 4 0
6 11 10 4
6 4 82...

output:

2 9 1 
3 9 1 2 
2 9 3 
3 9 7 4 
3 9 1 5 
2 9 6 
2 9 7 
3 9 3 8 
1 9 
3 9 1 10 
3 9 7 11 

result:

wrong answer wrong solution for vertex 6