QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#875742 | #10023. Kangaroo On Graph | asdfsdf# | WA | 312ms | 79088kb | C++23 | 2.5kb | 2025-01-30 11:45:52 | 2025-01-30 11:45:52 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define MOD 998244353
#define MAX 4020202
map<pii, int> mp;
pii edges[MAX];
int W[MAX];
vector<int> nxt[MAX];
vector<int> gph[MAX];
vector<pii> adj[MAX];
int eloc[MAX];
int cnt;
int ch[MAX][2];
int init(int v, int s, int e, int loc) {
if (s == e) {
adj[loc].emplace_back(gph[v][s], W[gph[v][s]]);
return loc;
}
int m = s + e >> 1;
adj[loc].emplace_back(ch[loc][0] = init(v, s, m, ++cnt), 0);
adj[loc].emplace_back(ch[loc][1] = init(v, m + 1, e, ++cnt), 0);
return loc;
}
void add(int v, int edge, int s, int e, int l, int r, int loc) {
if (e < l || r < s) return;
if (l <= s && e <= r) {
adj[edge].emplace_back(loc, 0);
return;
}
int m = s + e >> 1;
add(v, edge, s, m, l, r, ch[loc][0]);
add(v, edge, m + 1, e, l, r, ch[loc][1]);
}
ll dist[MAX];
int vis[MAX];
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int N, M;
cin >> N >> M;
int i, a, b, c;
for (i = 1; i <= M; i++) {
cin >> a >> b;
eloc[i] = gph[a].size();
gph[a].push_back(i);
edges[i] = pii(a, b);
cin >> W[i];
mp[pii(a, b)] = i;
}
cnt = N + M;
for (i = 1; i <= N; i++) {
if (gph[i].empty()) continue;
int d = gph[i].size();
init(i, 0, d - 1, i + M);
}
int K;
cin >> K;
for (i = 1; i <= K; i++) {
cin >> a >> b >> c;
int e1, e2;
e1 = mp[pii(a, b)];
e2 = mp[pii(b, c)];
nxt[e1].push_back(eloc[e2]);
}
for (i = 1; i <= M; i++) {
int nv = edges[i].second;
if (nxt[i].empty()) adj[i].emplace_back(nv + M, 0);
else {
int p = -1;
for (auto l : nxt[i]) {
if (p + 1 < l) add(nv, i, 0, (int)gph[nv].size() - 1, p + 1, l - 1, nv + M);
p = l;
}
if (p + 1 < gph[nv].size()) add(nv, i, 0, (int)gph[nv].size() - 1, p + 1, (int)gph[nv].size() - 1, nv + M);
}
}
for (i = 1; i <= cnt; i++) dist[i] = 1e18;
typedef pair<ll, int> pli;
priority_queue<pli, vector<pli>, greater<pli>> pq;
for (i = 1; i <= M; i++) {
if (edges[i].first == 1) {
dist[i] = W[i];
pq.emplace(W[i], i);
}
}
while (pq.size()) {
auto t = pq.top().second;
pq.pop();
if (vis[t]) continue;
vis[t] = 1;
for (auto& [v, w] : adj[t]) {
if (dist[v] > dist[t] + w) {
dist[v] = dist[t] + w;
pq.emplace(dist[v], v);
}
}
}
ll ans = 1e18;
for (i = 1; i <= M; i++) if (edges[i].second == N) ans = min(ans, dist[i]);
if (ans <= 1e17) cout << ans;
else cout << -1;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 11ms
memory: 14064kb
input:
4 4 1 3 2 1 2 3 2 4 3 3 4 3 1 1 3 4
output:
6
result:
ok answer is '6'
Test #2:
score: 0
Accepted
time: 11ms
memory: 13932kb
input:
7 8 1 3 5 1 2 2 3 4 1 2 4 1 4 5 6 4 6 2 5 7 1 6 7 1 2 3 4 5 2 4 6
output:
9
result:
ok answer is '9'
Test #3:
score: 0
Accepted
time: 11ms
memory: 11788kb
input:
4 3 1 2 3 2 3 4 3 4 1 1 1 2 3
output:
-1
result:
ok answer is '-1'
Test #4:
score: 0
Accepted
time: 303ms
memory: 72952kb
input:
150001 200000 27259 27261 590380540 62249 62251 781612972 142049 142051 869916317 21557 21559 882107330 43939 43940 906862353 13835 13837 750774554 85358 85360 468362257 42743 42745 653927711 25898 25900 427788655 9457 9459 600827054 80848 80850 853444790 84751 84753 490887034 142664 142666 26367087...
output:
49897302829745
result:
ok answer is '49897302829745'
Test #5:
score: 0
Accepted
time: 191ms
memory: 58676kb
input:
100000 133332 94634 94636 273916875 49405 49406 7705623 46579 46580 613041575 97379 97381 277397584 86487 86488 446200817 7618 7619 82676219 79763 79765 265220769 49775 49777 175656241 50253 50254 509685344 64341 64342 642442592 81789 81790 7720070 59791 59792 190513484 92339 92341 839361674 83696 8...
output:
33346820813893
result:
ok answer is '33346820813893'
Test #6:
score: 0
Accepted
time: 312ms
memory: 79088kb
input:
149998 199996 84723 84724 160637000 143893 143894 382237567 128673 128674 229111160 87169 87171 186600504 103309 103311 415954689 65442 65443 895315674 71846 71848 882228834 69164 69166 953310617 30360 30361 433585279 126633 126634 77552169 102808 102809 858368884 123704 123706 492180159 142672 1426...
output:
49784186835101
result:
ok answer is '49784186835101'
Test #7:
score: -100
Wrong Answer
time: 98ms
memory: 23596kb
input:
10023 20040 1 1646 1646 1 4408 4408 1 4109 4109 4019 10002 4019 1 2876 2876 1 8613 8613 1 2766 2766 1537 10002 1537 1 3584 3584 1 696 696 1 5648 5648 8667 10002 8667 1 9008 9008 6467 10002 6467 1 1231 1231 1 4290 4290 7054 10002 7054 7021 10002 7021 10007 10023 10007 1 4912 4912 1 5670 5670 2352 100...
output:
20010
result:
wrong answer expected '40008', found '20010'