QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#165959 | #5506. Hyperloop | arseny_y# | WA | 5ms | 10940kb | C++23 | 3.0kb | 2023-09-05 23:40:59 | 2023-09-05 23:40:59 |
Judging History
answer
//I wrote this code 4 u today
#include <bits/stdc++.h>
template<class t> using vc = std::vector<t>;
#define nd node*
#define pnd pair<nd, nd>
typedef long long ll;
template<const ll MOD>
struct mod_mul : std::multiplies<const ll> {
ll operator()(const ll a, const ll b) {
return (a * b) % MOD;
}
};
template<typename T>
inline void sort(T &a) {
std::sort(a.begin(), a.end());
}
template<typename T>
inline void unique(T &a) {
a.resize(std::unique(a.begin(), a.end()) - a.begin());
}
template<typename T>
inline void reverse(T &a) {
std::reverse(a.begin(), a.end());
}
const ll INF = 9023372036854775808ll;
const ll MOD = 1000000007ll;
using namespace std;
const int MAXN = 1e5 + 228;
vector<pair<int, int>> g[MAXN];
vector<pair<int,int>> ng[MAXN];
vector<int> usd(MAXN, false), nxt(MAXN, -1);
vector<int> dp[MAXN];
void dfs(int v = 1) {
for (auto &[to, w] : ng[v]) {
dfs(to);
}
for (auto &[to, w] : ng[v]) {
vector<int> cur = dp[to];
vector<int> ncur;
if (!cur.empty() && w > cur[0]) {
cur.insert(cur.begin(), w);
} else if (!cur.empty()) {
for (int i = 0; i < cur.size(); ++i) {
ncur.push_back(cur[i]);
if (i == cur.size() - 1 || cur[i] >= w && w >= cur[i + 1]) {
ncur.push_back(w);
}
}
swap(cur, ncur);
} else {
cur = {w};
}
if (cur > dp[v]) {
dp[v] = cur;
nxt[v] = to;
}
}
}
int32_t main() {
std::cin.tie(nullptr)->ios_base::sync_with_stdio(false);
ll t;
cin >> t;
while (t--) {
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
g[i].clear(), ng[i].clear();
}
while (m--) {
int x, y, w;
cin >> x >> y >> w;
g[x].emplace_back(y, w);
g[y].emplace_back(x, w);
}
priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
q.emplace(0, 1);
vector<int> d(n + 1, INT_MAX);
d[1] = 0;
while (!q.empty()) {
auto [curd, v] = q.top();
q.pop();
for (auto &[to, w] : g[v]) {
if (d[v] + w < d[to]) {
d[to] = d[v] + w;
q.emplace(d[to], to);
}
}
}
for (int i = 1; i <= n; ++i) {
nxt[i] = -1;
for (auto &[to, w] : g[i]) {
if (d[to] == d[i] + w) {
ng[i].push_back({to, w});
}
}
}
dfs();
int nw = 1;
cout << dp[1].size() + 1 << '\n';
for (int i = 0; i < dp[1].size(); ++i) {
cout << nw << ' ';
nw = nxt[nw];
}
cout << n;
cout << '\n';
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 10940kb
input:
2 4 6 1 2 1 1 3 2 2 3 1 2 4 2 3 4 1 1 4 4 6 11 1 2 9 2 3 12 3 4 3 4 5 5 5 6 10 6 1 22 2 4 9 3 6 1 4 6 5 2 5 2 3 5 8
output:
3 1 2 4 6 1 2 5 3 -1 6
result:
wrong answer Integer -1 violates the range [1, 6] (test case 2)