QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#189853 | #2879. Kaleidoscopic Route | Beevo | WA | 2ms | 7984kb | C++20 | 2.6kb | 2023-09-28 00:42:05 | 2023-09-28 00:42:05 |
Judging History
answer
#include <bits/stdc++.h>
#define el '\n'
#define Beevo ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e5 + 5, INF = 1e9;
vector<pair<int, int>> g[N];
int n, m, dist[N][2], mn[N][2], preMn[N][2];
void pre() {
for (int i = 1; i <= n; i++) {
for (int j = 0; j < 2; j++) {
mn[i][j] = INF;
dist[i][j] = INF;
}
}
}
void dijMin(int u, int st) {
priority_queue<pair<pair<int, int>, int>> pq;
dist[u][st] = 0;
preMn[u][st] = 0;
pq.push({{0, -INF}, u});
int c, curMn;
while (pq.size()) {
tie(c, curMn) = pq.top().first;
u = pq.top().second;
c *= -1, curMn *= -1;
pq.pop();
if (dist[u][st] != c || mn[u][st] != curMn)
continue;
for (auto &v: g[u]) {
if (c + 1 < dist[v.first][st] || c + 1 == dist[v.first][st] && min(curMn, v.second) < mn[v.first][st]) {
dist[v.first][st] = c + 1, mn[v.first][st] = min(curMn, v.second), preMn[v.first][st] = u;
pq.push({{-dist[v.first][st], -mn[v.first][st]}, v.first});
}
}
}
}
void testCase() {
cin >> n >> m;
int u, v, c;
vector<pair<pair<int, int>, int>> edges;
for (int i = 0; i < m; i++) {
cin >> u >> v >> c;
g[u].emplace_back(v, c);
g[v].emplace_back(u, c);
edges.push_back({{u, v}, c});
}
pre();
dijMin(1, 0), dijMin(n, 1);
int sol = -1;
pair<int, int> e;
for (auto &i: edges) {
u = i.first.first, v = i.first.second, c = i.second;
if (dist[u][0] + dist[v][1] + 1 == dist[n][0]) {
int cur = i.second - min({mn[u][0], mn[v][1], i.second});
if (cur > sol)
sol = cur, e = i.first;
}
swap(u, v);
if (dist[u][0] + dist[v][1] + 1 == dist[n][0]) {
int cur = i.second - min({mn[u][0], mn[v][1], i.second});
if (cur > sol)
sol = cur, e = i.first;
}
}
u = e.first, v = e.second;
vector<int> p;
while (v)
p.push_back(v), v = preMn[v][1];
reverse(p.begin(), p.end());
while (u)
p.push_back(u), u = preMn[u][0];
reverse(p.begin(), p.end());
cout << p.size() - 1 << el;
for (auto &i: p)
cout << i << ' ';
}
signed main() {
Beevo
int t = 1;
// cin >> t;
while (t--)
testCase();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 6968kb
input:
6 8 1 5 2 5 2 5 3 5 4 1 3 10 3 4 6 4 5 7 4 6 8 2 6 1
output:
3 1 5 4 6
result:
ok 3 6
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 7984kb
input:
10 20 1 9 34 6 3 80 7 3 15 5 4 73 4 1 42 8 6 92 2 10 25 4 3 8 9 3 79 3 1 11 9 2 74 10 1 83 3 2 6 10 3 38 10 4 48 1 5 38 6 2 43 4 2 55 8 7 90 3 5 4
output:
3 1 10 1 10
result:
wrong answer jury has better answer