QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784112 | #8874. Labelled Paths | alexhamidi | WA | 0ms | 3552kb | C++20 | 1.6kb | 2024-11-26 13:27:25 | 2024-11-26 13:27:26 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
using namespace std;
const int INF = numeric_limits<int>::max();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, d, s;
cin >> n >> m >> d >> s;
string A;
cin >> A;
vector<vector<pair<string, int>>> adj(n+1);
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});
}
for (int target = 1; target <= n; target++) {
vector<int> dist(n+1, INF);
vector<int> prev(n+1, -1);
dist[s] = 0;
queue<pair<int, string>> q;
q.push({s, ""});
while (!q.empty()) {
auto [node, currentPath] = q.front();
q.pop();
if (node == target) break;
for (auto [edgeLabel, nextNode] : adj[node]) {
if (dist[nextNode] > dist[node] + 1) {
dist[nextNode] = dist[node] + 1;
prev[nextNode] = node;
q.push({nextNode, currentPath + edgeLabel});
}
}
}
if (dist[target] == INF) {
cout << 0 << "\n";
} else {
vector<int> path;
for (int at = target; at != -1; at = prev[at]) {
path.push_back(at);
}
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: 3552kb
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 6 2 2 9 3 3 9 6 4 3 9 7 5 2 9 6 2 9 7 3 9 3 8 1 9 3 9 1 10 3 9 6 11
result:
wrong answer wrong solution for vertex 2