QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#793855 | #8874. Labelled Paths | alexhamidi | WA | 0ms | 3580kb | C++20 | 1.5kb | 2024-11-30 02:44:18 | 2024-11-30 02:44:18 |
Judging History
answer
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
using namespace std;
struct Edge {
int to;
int l;
int p;
};
int main() {
int n, m, d, s;
cin >> n >> m >> d >> s;
s--;
string A;
cin >> A;
vector<vector<Edge>> adj(n);
for (int i = 0; i < m; i++) {
int u, v, l, p;
cin >> u >> v >> p >> l;
u--, v--, p--;
adj[u].push_back({v, l, p});
}
vector<vector<int>> bestPath(n); // Best path to each node
bestPath[s].push_back(s); // Start with the source node
queue<int> q;
q.push(s);
while (!q.empty()) {
int curr = q.front();
q.pop();
for (const auto& edge : adj[curr]) {
int next = edge.to;
vector<int> candidatePath = bestPath[curr]; // Copy the current best path
candidatePath.push_back(next);
if (bestPath[next].empty() || lexicographical_compare(candidatePath.begin(), candidatePath.end(), bestPath[next].begin(), bestPath[next].end())) {
bestPath[next] = candidatePath; // Update with the better path
q.push(next);
}
}
}
for (int i = 0; i < n; i++) {
if (bestPath[i].empty()) {
cout << "0\n";
} else {
cout << bestPath[i].size() << " ";
for (int node : bestPath[i]) cout << node + 1 << " ";
cout << "\n";
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3580kb
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 3 9 1 3 3 9 1 4 3 9 1 5 4 9 1 5 6 2 9 7 4 9 1 3 8 1 9 3 9 1 10 5 9 1 5 6 11
result:
wrong answer wrong solution for vertex 3