QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#449596 | #4898. 基础图论练习题 | wly09 | 4 | 112ms | 58124kb | C++14 | 1.8kb | 2024-06-21 15:14:06 | 2024-06-21 15:14:07 |
Judging History
answer
#include <algorithm>
#include <bitset>
#include <cstdint>
#include <iostream>
#include <numeric>
#include <vector>
#include <utility>
using namespace std;
const int N = 2e5 + 8;
const int p = 998244353;
int64_t n, m, q;
vector<pair<int64_t, int64_t> > gg[N];
vector<pair<int64_t, pair<int64_t, int64_t> > > vec;
int fa[N], siz[N];
inline void init(int n) {
iota(fa, fa + n + 1, 0), fill(siz, siz + n + 1, 1);
}
int ask(int x) {
return fa[x] == x? x: fa[x] = ask(fa[x]);
}
void merge(int x, int y) {
int a = ask(x), b = ask(y);
if (a == b) return ;
if (siz[a] > siz[b]) swap(a, b);
fa[a] = b;
siz[b] += siz[a];
}
bitset<N> vis;
void dfs(int x) {
if (vis[x]) return ;
vis[x] = true;
for (auto p: gg[x])
dfs(p.first);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> q;
for (int i = 0; i < m; ++i) {
int64_t d, x;
cin >> d >> x;
for (int j = 0; j + d < n; ++j) {
vec.push_back(make_pair(x, make_pair(j, j + d)));
gg[j].push_back(make_pair(j + d, x));
gg[j + d].push_back(make_pair(j, x));
}
}
for (int i = 0; i < q; ++i) {
int64_t u, v, w;
cin >> u >> v >> w;
vec.push_back(make_pair(w, make_pair(u, v)));
gg[u].push_back(make_pair(v, w));
gg[v].push_back(make_pair(u, w));
}
int64_t kk = 0;
for (int i = 0; i < n; ++i) {
if (!vis[i]) ++kk;
dfs(i);
}
clog << kk << endl;
sort(vec.begin(), vec.end());
kk = n - kk;
int64_t tt = 0, sum = 0;
init(n);
for (auto e: vec) {
if (ask(e.second.first) == ask(e.second.second)) continue;
merge(e.second.first, e.second.second);
sum += e.first;
if (sum >= p) sum -= p;
++tt;
if (tt == kk) break;
}
cout << sum << '\n';
return 0;
}
詳細信息
Subtask #1:
score: 4
Accepted
Test #1:
score: 4
Accepted
time: 59ms
memory: 34076kb
input:
161199 9 46510 147335 540442844 159493 801351455 149342 821625305 128476 843250712 95524 275754315 139315 106523502 93575 680460786 155498 328812257 146020 410466645 79992 141967 50596784 152210 68644 268349216 72549 96959 42994091 93869 27394 945120577 2909 81886 270684270 12735 35026 871917997 974...
output:
359714743
result:
ok 1 number(s): "359714743"
Test #2:
score: 0
Accepted
time: 112ms
memory: 58124kb
input:
168549 9 49402 160577 34610415 114623 670751010 74448 676966248 53782 845469137 130729 375561046 31610 261496571 134601 154875802 136129 905308676 166248 499420220 69637 72676 875637640 160442 125460 1269794 146261 61770 714794725 137610 1291 490170432 162092 81850 488118013 106400 48193 276190368 4...
output:
520439176
result:
ok 1 number(s): "520439176"
Test #3:
score: 0
Accepted
time: 92ms
memory: 48532kb
input:
127164 9 45109 56483 490066497 70966 229077054 87305 993081887 72423 442762798 80262 200507011 101712 162752728 67532 590730535 44956 565466274 124237 429166816 13030 8906 742024040 97259 101468 187678659 13401 4301 143856524 125750 80473 258719294 106155 10339 592121345 120034 92354 50915550 112430...
output:
211463174
result:
ok 1 number(s): "211463174"
Test #4:
score: 0
Accepted
time: 74ms
memory: 41144kb
input:
158784 9 48415 138305 177767002 147417 50196642 85527 776201932 144377 990389932 118355 310906417 145220 218744495 145002 132736644 51947 834751363 139733 839880491 158443 157692 159261414 111518 14927 747973081 37498 66196 69874791 11597 115114 22394413 16704 133459 109302190 112143 46551 813021872...
output:
151875883
result:
ok 1 number(s): "151875883"
Test #5:
score: 0
Accepted
time: 21ms
memory: 12804kb
input:
111371 0 45933 13298 59545 852258097 94111 54245 459369673 40744 23311 644404848 37039 92443 220984611 17374 43165 421794343 57652 57965 470479953 62977 14481 563172671 102144 3471 36594913 46628 43278 11508424 55965 80136 777230453 56962 35374 349098036 34825 27995 339605509 43021 17657 780921827 5...
output:
92500087
result:
ok 1 number(s): "92500087"
Subtask #2:
score: 0
Time Limit Exceeded
Dependency #1:
100%
Accepted
Test #6:
score: 0
Time Limit Exceeded
input:
191116 49595 45279 87483 815631830 153579 433065789 167569 346797140 98560 154881536 170720 13622837 133236 561208103 155537 421316363 140536 514298139 6005 986290017 154400 85233907 166826 351094521 174419 304435906 173900 61174962 112778 693574534 104503 745038995 134920 31228457 117606 662581798 ...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #11:
score: 0
Runtime Error
input:
569435269457904707 2 0 490445920091092693 772271583 144842828305643603 609043885
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Runtime Error
Test #31:
score: 0
Runtime Error
input:
755526150476311190 942 0 492334667739348527 1 755523898623296976 1 532486636690994793 1 755526150476030559 1 755526150476249097 1 502164090270592200 1 657422656495814703 1 487200614853438190 1 311037325561173142 1 755526150475651155 1 125287404340238660 1 755524914808674090 1 755526150476177007 1 75...
output:
result:
Subtask #6:
score: 0
Skipped
Dependency #3:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #5:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%