QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#188270 | #5492. Toll Roads | Beevo# | AC ✓ | 661ms | 99508kb | C++20 | 2.5kb | 2023-09-25 18:01:31 | 2023-09-25 18:01:32 |
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 = 2e5 + 5;
bool vis[N];
int solA[N], solB[N];
vector<pair<int, int>> curQueries;
vector<pair<int, int>> queries[N];
struct DSU {
vector<int> sz, par;
vector<set<int>> comp;
DSU() {
sz.resize(N);
par.resize(N);
comp.resize(N);
for (int i = 0; i < N; i++)
par[i] = i, sz[i] = 1, comp[i].insert(i);
}
int findSet(int u) {
if (u == par[u])
return u;
return par[u] = findSet(par[u]);
}
void unionSet(int u, int v, int c) {
u = findSet(u);
v = findSet(v);
if (u != v) {
if (sz[u] < sz[v])
swap(u, v);
par[v] = u;
sz[u] += sz[v];
for (auto &w: comp[v]) {
comp[u].insert(w);
for (auto &i: queries[w]) {
if (vis[i.first] || comp[u].find(i.second) == comp[u].end())
continue;
vis[i.first] = 1, solA[i.first] = c;
curQueries.emplace_back(i.first, w);
}
}
}
}
} dsu;
struct Edge {
int u, v, c;
bool operator < (Edge &e) const {
return c < e.c;
}
};
void testCase() {
int n, m, q;
cin >> n >> m >> q;
vector<Edge> edges(m);
for (int i = 0; i < m; i++)
cin >> edges[i].u >> edges[i].v >> edges[i].c;
sort(edges.begin(), edges.end());
for (int i = 0; i < q; i++) {
int u, v;
cin >> u >> v;
queries[u].emplace_back(i, v);
queries[v].emplace_back(i, u);
}
for (int i = 0; i < m; i++) {
dsu.unionSet(edges[i].u, edges[i].v, edges[i].c);
if (i + 1 >= m || edges[i + 1].c != edges[i].c) {
while (curQueries.size()) {
solB[curQueries.back().first] = dsu.comp[dsu.findSet(curQueries.back().second)].size();
curQueries.pop_back();
}
}
}
for (int i = 0; i < q; i++)
cout << solA[i] << ' ' << solB[i] << el;
}
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: 6ms
memory: 29848kb
input:
4 3 6 1 2 1 2 3 3 3 4 2 1 2 1 3 1 4 2 3 2 4 3 4
output:
1 2 3 4 3 4 3 4 3 4 2 2
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 373ms
memory: 97640kb
input:
200000 199999 200000 40203 148773 165038 148773 54931 77889 54931 9912 192188 9912 180491 24730 180491 77332 36976 77332 43929 146532 43929 43341 172446 43341 141304 121793 141304 105828 148202 105828 72010 107746 72010 152016 156358 152016 150074 115703 150074 117105 73900 117105 57831 59264 57831 ...
output:
165038 3 77889 2 192188 41 24730 2 36976 3 146532 4 172446 20 121793 2 148202 4 107746 2 156358 10 115703 6 73900 5 59264 2 67443 4 26999 2 156979 16 80963 3 56618 2 107615 6 63765 3 19719 2 178439 35 95141 5 72029 4 14650 2 21437 3 109944 6 139220 7 141978 9 102949 2 170997 15 100704 3 75249 2 1312...
result:
ok 200000 lines
Test #3:
score: 0
Accepted
time: 458ms
memory: 99508kb
input:
200000 199999 200000 25566 162429 116811 162429 150239 28436 150239 75366 140258 75366 176680 111452 176680 158813 50710 158813 125248 118834 125248 191706 31210 191706 163115 65321 163115 46167 44831 46167 129128 79156 129128 112971 51160 112971 195397 1773 195397 196884 159329 196884 188278 191759...
output:
116811 3 28436 2 140258 13 118834 10 118834 10 118834 10 191759 21 159329 14 79156 7 159329 14 191759 21 159329 14 159329 14 191759 21 95051 2 197843 41 46441 2 197843 41 197843 41 197843 41 197843 41 179891 15 173651 10 132452 7 179891 15 84295 3 179891 15 173651 10 179891 15 179891 15 179891 15 18...
result:
ok 200000 lines
Test #4:
score: 0
Accepted
time: 642ms
memory: 96388kb
input:
200000 199999 200000 108049 140092 177196 140092 142782 104903 142782 144052 130828 144052 105524 197299 105524 146641 105000 146641 126120 6587 126120 23329 185363 23329 145087 162872 145087 189421 141021 189421 96046 167286 96046 67072 147548 67072 7773 150238 7773 157376 141227 157376 3589 103113...
output:
199998 166739 199998 166739 199997 137953 199999 200000 199961 33049 199991 65901 199995 31759 199999 200000 199991 65901 199998 166739 199997 137953 199998 166739 199999 200000 199997 137953 199999 200000 199978 17913 199997 137953 199981 18397 199997 137953 199990 21472 199927 1556 199998 166739 1...
result:
ok 200000 lines
Test #5:
score: 0
Accepted
time: 38ms
memory: 35812kb
input:
2 1 200000 2 1 0 1 2 1 2 2 1 2 1 2 1 2 1 2 1 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 1 2 2 1 1 2 1 2 1 2 1 2 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 1 2 2 1 1 2 1 2 1 2 2 1 1 2 1 2 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 1 2 1 2 2 1 2 1 2 1 1 2 2 1 2 1 2 1 1 2 1 2 1 2...
output:
0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 0 2 ...
result:
ok 200000 lines
Test #6:
score: 0
Accepted
time: 38ms
memory: 35904kb
input:
2 1 200000 2 1 200000 2 1 1 2 1 2 2 1 2 1 1 2 1 2 1 2 1 2 1 2 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 2 1 1 2 2 1 2 1 1 2 1 2 1 2 1 2 2 1 2 1 2 1 2 1 1 2 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 1 2 2 1 2 1 1 2 2 1 1 2 2 1 1 2 2 1 1 2 2 1 2 1 1 2 2 1 1 2 2 1 2 1 1 2 1 2 1 ...
output:
200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200000 2 200...
result:
ok 200000 lines
Test #7:
score: 0
Accepted
time: 292ms
memory: 48052kb
input:
200000 199999 199999 107673 108777 137731 161326 2822 185976 42519 186329 11368 2875 128189 40207 660 17140 174600 80080 45700 24002 103478 55840 94897 141771 83861 106266 190280 61753 130887 100340 51796 36679 85897 157537 68633 179542 133431 726 4727 100325 68158 196602 138158 15657 61216 85366 13...
output:
182636 182638 188210 188212 102022 102024 92251 92253 156363 156365 56753 56755 160474 160476 43371 43373 78661 78663 102391 102393 87733 87735 50624 50626 167931 167933 163802 163804 30413 30415 9548 9550 125354 125356 66593 66595 12746 12748 172788 172790 150755 150757 175783 175785 198133 198135 ...
result:
ok 199999 lines
Test #8:
score: 0
Accepted
time: 100ms
memory: 38224kb
input:
632 199396 199396 528 623 151485 126 300 71970 423 596 177223 239 363 43731 126 129 43760 167 445 129222 81 349 53617 255 594 20913 222 468 187290 40 424 196898 182 202 97262 57 276 187115 20 125 84603 196 281 60208 91 159 68556 70 370 62697 64 519 173483 132 525 149142 501 581 7624 423 523 151709 9...
output:
383 254 518 456 986 600 740 559 391 328 716 551 312 18 439 379 530 469 1365 623 678 539 522 464 1003 604 498 437 1245 618 531 472 357 196 465 410 363 218 380 244 983 599 487 427 417 353 566 487 640 529 382 247 361 199 678 539 531 472 732 558 1006 605 391 328 344 181 570 490 436 377 439 379 363 218 6...
result:
ok 199396 lines
Test #9:
score: 0
Accepted
time: 269ms
memory: 48512kb
input:
100000 200000 200000 52858 70914 35062 99437 57982 31435 95724 61978 154826 80071 97428 180435 37559 41986 186600 82330 60710 46299 50361 2041 11824 97939 7216 68467 27360 20298 20367 22901 33604 152232 85363 46295 36133 7948 46833 105272 62600 12092 16575 68460 39871 29788 88827 76407 41346 84845 7...
output:
65422 31036 156936 98628 119689 91378 82807 65139 70554 43803 163978 99182 103626 84209 66822 34554 88936 72340 127128 93765 76755 56084 77303 56989 128035 94040 73388 50011 66219 32835 120774 91787 79431 60407 114700 89562 81951 64046 136949 96038 66867 34668 64709 28903 74431 51949 69879 42315 628...
result:
ok 200000 lines
Test #10:
score: 0
Accepted
time: 661ms
memory: 99316kb
input:
200000 199999 200000 185243 33784 95622 46781 107802 42086 149014 198625 45412 159192 1231 32912 68503 148649 106263 135161 27908 168574 180133 12562 165333 72353 160550 156077 4001 45858 48858 9451 6397 160416 160375 122402 112610 176893 162254 46641 199087 36919 21 111525 125696 147048 53720 73845...
output:
199997 195765 199997 195765 199979 33236 199997 195765 199997 195765 199997 195765 199997 195765 199997 195765 199991 83259 199976 39425 199997 195765 199985 73860 199836 6767 199976 39425 199997 195765 199997 195765 199995 107073 199999 200000 199995 107073 199997 195765 199991 83259 199997 195765 ...
result:
ok 200000 lines
Test #11:
score: 0
Accepted
time: 464ms
memory: 67016kb
input:
200000 199999 200000 83491 93406 16020 160288 46393 68815 150261 39524 106233 89684 101484 186710 72901 167375 69517 145319 54171 130836 162903 176302 16129 125258 135455 35814 139578 70344 196425 57001 26850 8975 169239 113975 97460 148216 182789 49380 42991 128149 196748 166876 93306 88264 119844 ...
output:
194278 141013 194278 141013 198809 187567 196050 157285 191419 114070 199593 196267 198296 179544 174557 31900 198534 184764 177605 40570 190205 104254 181247 58841 188794 95616 198534 184764 198523 181455 189467 100962 198385 180269 198187 178863 197299 168100 189577 101808 196540 162472 194278 141...
result:
ok 200000 lines
Test #12:
score: 0
Accepted
time: 133ms
memory: 49340kb
input:
200000 199999 199999 143668 143669 143668 11617 11618 11617 37034 37035 37034 185348 185349 185348 136887 136888 136887 188027 188028 188027 103206 103207 103206 145144 145145 145144 67513 67514 67513 167655 167656 167655 187910 187911 187910 30298 30299 30298 162829 162830 162829 182915 182916 1829...
output:
146312 146313 160448 160449 100437 100438 54296 54297 160211 160212 59722 59723 117676 117677 178941 178942 49823 49824 63026 63027 90309 90310 35791 35792 171473 171474 62058 62059 74645 74646 128605 128606 17748 17749 166510 166511 100160 100161 43567 43568 67261 67262 163412 163413 164743 164744 ...
result:
ok 199999 lines
Test #13:
score: 0
Accepted
time: 148ms
memory: 49492kb
input:
200000 199999 199999 183516 183517 16484 31945 31946 168055 187198 187199 12802 36772 36773 163228 15314 15315 184686 157786 157787 42214 195409 195410 4591 117281 117282 82719 100043 100044 99957 146665 146666 53335 99315 99316 100685 32933 32934 167067 197914 197915 2086 45372 45373 154628 101825 ...
output:
90837 90838 97994 97995 131658 131659 30073 30074 183244 183245 199094 199095 109081 109082 154046 154047 28222 28223 48271 48272 64951 64952 62521 62522 119663 119664 4898 4899 177650 177651 89865 89866 171354 171355 182452 182453 88348 88349 126662 126663 128475 128476 130436 130437 80054 80055 66...
result:
ok 199999 lines
Test #14:
score: 0
Accepted
time: 375ms
memory: 53448kb
input:
200000 199999 200000 537 134680 44756 92989 25467 154790 13052 50779 79699 166373 158353 130816 156718 74433 103072 128309 109704 100153 136756 179599 162791 78195 95533 171942 188130 4999 130076 22750 130455 80673 142159 104070 163798 179861 46359 113175 75257 124953 34160 178575 159252 187249 1736...
output:
174341 149634 147053 105841 191645 184741 142739 100177 185016 171148 103475 52785 197319 193762 170693 142439 164832 133195 185016 171148 140100 96192 183052 165345 187830 175382 168226 138890 124364 73840 85566 35859 173534 148362 191594 184115 180547 159882 147053 105841 168226 138890 145794 1036...
result:
ok 200000 lines
Test #15:
score: 0
Accepted
time: 249ms
memory: 44052kb
input:
100000 200000 200000 61665 95293 34999 92437 17782 30456 94649 79809 163444 90369 26124 111763 61665 59107 9953 61665 40182 69232 48130 75359 143570 59858 4110 70372 61665 83820 157303 39647 77218 46638 88075 59632 2355 72951 22972 159732 61665 72281 182488 70854 43327 166254 73926 9030 19560 90890 ...
output:
110869 82103 152800 94332 181924 98533 124286 87097 126509 87801 57899 45494 107467 80599 50946 38961 86954 69113 90847 71632 66580 53139 139648 91527 74771 60099 65603 52269 115982 84155 99002 76184 62114 49297 36851 26020 39292 28159 64938 51732 85874 68399 82468 66037 104909 79349 67818 54236 113...
result:
ok 200000 lines
Test #16:
score: 0
Accepted
time: 265ms
memory: 48272kb
input:
100000 200000 200000 38574 81368 165468 5958 89291 58685 21278 55089 149933 22326 84479 118868 64584 5391 10008 76431 45431 43872 34083 16278 101144 78564 96999 26280 10560 7649 9300 97899 75637 109231 58936 8153 106816 18689 58323 56855 40790 96223 112950 54298 14681 7483 45472 5207 152518 60778 90...
output:
91289 74907 91600 75142 100593 81356 84971 69101 70889 49463 144734 95667 61879 28843 86868 70979 130886 93115 93186 76405 111174 86751 66769 40765 78920 61966 135463 94093 65769 38139 110719 86551 89907 73802 138514 94685 81430 65163 63020 32155 77014 59446 82826 66730 143615 95500 62373 29897 7320...
result:
ok 200000 lines