QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#660722 | #2804. Travel Guide | AngelOlan | WA | 0ms | 3828kb | C++20 | 1.9kb | 2024-10-20 12:56:47 | 2024-10-20 12:56:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
// BRO
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
#define pb push_back
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
#define FOR(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define ROF(i, a, b) for (int i = (int)a-1; i >= (int)b; --i)
#define ENDL '\n'
#define __ ios_base::sync_with_stdio(0); cin.tie(nullptr);
int main() { __
int n, m;
cin >> n >> m;
vector<vector<pi>> g(n, vector<pi>());
FOR (i, 0, m) {
int u, v, w;
cin >> u >> v >> w;
g[u].pb({v, w});
g[v].pb({u, w});
}
vector<vector<int>> d(n);
FOR (x, 0, 3) {
priority_queue<pi> pq;
pq.push({0, x});
vector<int> dist(n, 1e9);
dist[x] = 0;
while (!pq.empty()) {
auto [w, u] = pq.top();
w = -w;
pq.pop();
if (w > dist[u])
continue;
for (auto &[v, ww] : g[u]) {
if (w + ww >= dist[v])
continue;
dist[v] = w + ww;
pq.push({-dist[v], v});
}
}
FOR (i, 0, n)
d[i].pb(dist[i]);
}
FOR (i, 0, n)
sort(ALL(d[i]));
sort(ALL(d));
map<pair<int, int>, int> m1;
map<int, pair<int, int>> m2, m3;
FOR (i, 0, n) {
pi p = {d[i][1], d[i][2]};
if (!m1.count(p) || m1[p] > d[i][0])
m1[p] = d[i][0];
p = {d[i][0], d[i][1]};
if (!m2.count(d[i][2]) || m2[d[i][2]] > p)
m2[d[i][2]] = p;
p = {d[i][1], d[i][0]};
if (!m3.count(d[i][2]) || m3[d[i][2]] > p)
m3[d[i][2]] = p;
}
int ans = 0;
FOR (i, 0, n) {
pi p = {d[i][1], d[i][2]};
if (m1[p] < d[i][0])
continue;
p = {d[i][0], d[i][1]};
pi p2 = m2[d[i][2]], p3 = m3[d[i][2]];
swap(p3.first, p3.second);
if (p > p2 || p > p3)
continue;
ans++;
}
cout << ans << ENDL;
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3576kb
input:
5 4 0 3 1 1 3 1 2 3 1 4 3 1
output:
4
result:
ok single line: '4'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3572kb
input:
5 6 0 3 1 1 3 1 2 3 1 4 3 1 0 1 1 0 2 1
output:
3
result:
ok single line: '3'
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3828kb
input:
20 55 3 13 74 1 3 72 1 15 63 0 15 62 0 14 59 2 14 56 2 19 80 11 19 83 6 11 70 6 10 74 10 17 67 7 17 77 7 9 87 9 18 97 12 18 78 4 12 70 4 5 83 5 16 85 8 16 86 8 13 72 14 19 60 0 19 99 0 18 80 8 18 90 5 8 88 3 16 77 3 12 86 2 12 67 2 10 56 9 10 66 9 11 66 7 11 90 7 15 58 4 15 71 1 4 94 1 13 70 13 17 1...
output:
17
result:
wrong answer 1st lines differ - expected: '7', found: '17'