QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784114 | #8874. Labelled Paths | alexhamidi | WA | 0ms | 3596kb | C++20 | 2.1kb | 2024-11-26 13:29:53 | 2024-11-26 13:29:54 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
int main() {
int n, m, d, s;
cin >> n >> m >> d >> s;
string A; // All edge labels are substrings of A
cin >> A;
vector<vector<pair<string, int>>> adj(n + 1); // {substring, target node}
for (int i = 0; i < m; i++) {
int u, v, p, l;
cin >> u >> v >> p >> l;
adj[u].push_back({A.substr(p - 1, l), v});
}
// Process each target node
for (int target = 1; target <= n; target++) {
queue<pair<int, string>> bfsQueue; // {current node, accumulated string}
vector<int> parent(n + 1, -1); // Parent for path reconstruction
vector<string> best(n + 1, string(d + 1, 'z')); // Best string to reach each node
vector<bool> visited(n + 1, false);
bfsQueue.push({s, ""});
best[s] = "";
visited[s] = true;
while (!bfsQueue.empty()) {
auto [node, curString] = bfsQueue.front();
bfsQueue.pop();
if (node == target) continue; // Skip further processing for the target
for (auto [edge, neighbor] : adj[node]) {
string newString = curString + edge;
// Check if the new path is better
if (newString < best[neighbor] && newString.size() <= d) {
best[neighbor] = newString;
parent[neighbor] = node;
bfsQueue.push({neighbor, newString});
}
}
}
// Output result for target
if (best[target] == string(d + 1, 'z')) {
cout << 0 << "\n"; // No path found
} else {
vector<int> path;
for (int v = target; v != -1; v = parent[v]) {
path.push_back(v);
}
reverse(path.begin(), path.end());
cout << path.size() << " ";
for (int node : path) {
cout << node << " ";
}
cout << "\n";
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3596kb
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 3 9 1 6 2 9 7 4 9 7 11 8 1 9 3 9 1 10 3 9 7 11
result:
wrong answer wrong solution for vertex 8