QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#153786 | #7050. Toad's Travel | PetroTarnavskyi# | AC ✓ | 94ms | 27032kb | C++17 | 2.1kb | 2023-08-30 23:23:56 | 2023-08-30 23:23:58 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a) - 1; i >= (b); i--)
#define FILL(a, b) memset(a, b, sizeof(a))
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
const int N = 1 << 17;
const int M = 1 << 18;
const LL LINF = 1.1e18;
vector<PII> g[N];
int used[N];
PII par[N];
int tin[N], fup[N], timer;
LL depth[N];
vector<PII> cycles[N];
set<pair<int, int>> bridges;
LL dp[N][2];
void dfs(int v, int p)
{
used[v] = 1;
tin[v] = fup[v] = timer++;
for (auto [to, w] : g[v])
{
if (to == p)
continue;
if (used[to] == 0)
{
par[to] = {v, w};
depth[to] = depth[v] + w;
dfs(to, v);
fup[v] = min(fup[v], fup[to]);
if (fup[to] == tin[to])
bridges.emplace(v, to);
}
else if (used[to] == 1)
{
cycles[to].emplace_back(v, w);
fup[v] = min(fup[v], tin[to]);
}
}
vector<LL> vec0, vec1;
for (auto [to, w] : g[v])
{
if (bridges.count(MP(v, to)))
{
vec0.push_back(dp[to][0] + 2 * w);
vec1.push_back(dp[to][1] + w);
}
}
for (auto [to, w] : cycles[v])
{
LL lenCycle = depth[to] - depth[v] + w;
LL s0 = 0;
for (int u = to; u != v; u = par[u].first)
{
s0 += dp[u][0];
}
LL val1 = LINF;
for (int u = to; u != v; u = par[u].first)
{
LL d = depth[u] - depth[v];
d = min(d, lenCycle - d);
val1 = min(val1, s0 + lenCycle - dp[u][0] + dp[u][1] + d);
}
vec0.push_back(s0 + lenCycle);
vec1.push_back(val1);
}
dp[v][0] = accumulate(ALL(vec0), 0LL);
dp[v][1] = dp[v][0];
FOR(i, 0, SZ(vec0))
dp[v][1] = min(dp[v][1], dp[v][0] - vec0[i] + vec1[i]);
used[v] = 2;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
FOR(i, 0, m)
{
int u, v, w;
cin >> u >> v >> w;
u--;
v--;
g[u].emplace_back(v, w);
g[v].emplace_back(u, w);
}
dfs(0, -1);
cout << dp[0][1] << "\n";
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 14168kb
input:
6 7 1 2 1 1 3 1 2 3 1 3 4 1 3 5 1 4 5 1 2 6 1
output:
8
result:
ok 1 number(s): "8"
Test #2:
score: 0
Accepted
time: 77ms
memory: 23360kb
input:
100000 100137 1 2 26499 2 3 28781 3 4 3027 2 5 30114 5 6 10466 4 7 3853 7 8 9974 1 9 24943 5 10 18202 3 11 17348 10 12 15857 1 13 21340 8 14 18936 13 15 14717 6 16 18707 12 17 14156 14 18 12128 18 19 29141 9 20 4504 20 21 1886 16 22 18314 3 23 124 7 24 3963 23 25 623 3 26 8555 7 27 5597 12 28 22923 ...
output:
3273176937
result:
ok 1 number(s): "3273176937"
Test #3:
score: 0
Accepted
time: 67ms
memory: 23948kb
input:
100000 100011 1 2 5629 2 3 7170 3 4 15000 1 5 4379 3 6 27183 6 7 11979 4 8 98 6 9 16523 6 10 26548 8 11 26623 3 12 16316 5 13 16600 3 14 11771 14 15 14562 2 16 30250 16 17 25990 7 18 7749 10 19 10815 6 20 17309 7 21 24531 14 22 12717 6 23 27225 4 24 4247 24 25 23624 3 26 28774 4 27 30501 4 28 24463 ...
output:
3277676018
result:
ok 1 number(s): "3277676018"
Test #4:
score: 0
Accepted
time: 80ms
memory: 23340kb
input:
100000 100294 1 2 31648 2 3 16857 1 4 18301 4 5 10003 5 6 2687 4 7 7844 2 8 6182 1 9 30270 2 10 30410 1 11 29852 1 12 19698 10 13 7674 13 14 28281 5 15 32041 7 16 12222 14 17 7806 17 18 6003 14 19 4838 12 20 3016 12 21 17635 2 22 15873 1 23 30279 17 24 28609 20 25 13539 11 26 18307 9 27 17791 10 28 ...
output:
3273517019
result:
ok 1 number(s): "3273517019"
Test #5:
score: 0
Accepted
time: 74ms
memory: 23792kb
input:
100000 101413 1 2 7253 1 3 25594 2 4 24952 1 5 12457 2 6 23879 3 7 30027 7 8 20050 7 9 12277 2 10 5400 4 11 5881 1 12 20267 10 13 14338 3 14 10341 5 15 30971 9 16 31404 9 17 20778 1 18 22827 3 19 1065 16 20 18909 18 21 13731 7 22 18652 19 23 9215 8 24 19166 15 25 2399 16 26 24755 12 27 23966 12 28 2...
output:
3256713324
result:
ok 1 number(s): "3256713324"
Test #6:
score: 0
Accepted
time: 81ms
memory: 22492kb
input:
100000 109768 1 2 16880 1 3 6582 2 4 3124 3 5 19956 5 6 26870 1 7 13148 4 8 3416 6 9 29072 3 10 21841 8 11 1027 11 12 2174 10 13 11785 6 14 13923 6 15 15503 10 16 28111 3 17 27255 10 18 28732 10 19 9447 7 20 18791 12 21 5908 11 22 13429 4 23 24904 21 24 17241 11 25 15671 21 26 8795 15 27 8672 14 28 ...
output:
3124265900
result:
ok 1 number(s): "3124265900"
Test #7:
score: 0
Accepted
time: 81ms
memory: 23592kb
input:
100000 105818 1 2 12109 2 3 3715 1 4 7198 2 5 25670 2 6 8403 5 7 13393 4 8 17885 7 9 30420 1 10 5643 9 11 14657 3 12 18301 7 13 1508 10 14 23885 7 15 30051 2 16 3999 7 17 8482 3 18 29926 1 19 9692 7 20 32424 13 21 8176 8 22 11524 6 23 5942 9 24 14277 1 25 15959 1 26 8402 19 27 18938 4 28 812 8 29 16...
output:
3164596468
result:
ok 1 number(s): "3164596468"
Test #8:
score: 0
Accepted
time: 81ms
memory: 23808kb
input:
100000 99999 1 2 5959 1 3 6362 1 4 4609 1 5 28891 4 6 27021 6 7 8994 5 8 8471 8 9 9743 9 10 24016 8 11 22780 5 12 23770 4 13 6924 9 14 17733 13 15 4508 1 16 8002 10 17 25402 3 18 16835 1 19 4935 18 20 21007 2 21 19374 12 22 3357 8 23 3418 20 24 4279 14 25 17743 7 26 19118 24 27 29582 21 28 9891 20 2...
output:
3286230800
result:
ok 1 number(s): "3286230800"
Test #9:
score: 0
Accepted
time: 79ms
memory: 23340kb
input:
100000 100298 1 2 21469 2 3 12107 1 4 28227 2 5 12483 2 6 20862 6 7 17226 2 8 3035 5 9 19060 5 10 12088 5 11 8949 9 12 5779 8 13 28775 2 14 8532 4 15 32254 11 16 22945 5 17 29186 13 18 26227 12 19 21010 6 20 28497 5 21 1653 9 22 1747 6 23 15626 5 24 6754 7 25 20626 7 26 6350 21 27 16229 9 28 20140 1...
output:
3258362208
result:
ok 1 number(s): "3258362208"
Test #10:
score: 0
Accepted
time: 1ms
memory: 11528kb
input:
9 10 1 2 1 2 3 1 2 4 1 3 5 1 4 5 1 5 6 1 6 7 2 6 8 2 7 8 2 8 9 100
output:
116
result:
ok 1 number(s): "116"
Test #11:
score: 0
Accepted
time: 1ms
memory: 15092kb
input:
7 9 1 2 1 1 3 1 2 3 1 3 4 1 3 5 1 4 5 1 5 6 1 5 7 1 6 7 1
output:
9
result:
ok 1 number(s): "9"
Test #12:
score: 0
Accepted
time: 74ms
memory: 22972kb
input:
98956 102296 49811 76153 31321 85570 93067 65488 15669 38736 42461 72156 68640 61551 28325 69589 5766 9579 5980 33759 44049 58211 48149 34230 721 50600 22099 95086 97821 77366 64344 81689 71714 36394 74365 16358 5030 53373 4813 8347 56549 72184 58332 5550 80428 25565 2865 68625 22433 18039 19634 729...
output:
7616880387
result:
ok 1 number(s): "7616880387"
Test #13:
score: 0
Accepted
time: 89ms
memory: 21804kb
input:
97431 107841 76826 54734 78719 59021 3529 35024 80723 10287 85494 55131 77063 11485 24438 45025 6178 6258 46539 77956 87464 85288 40443 35872 20081 86016 8161 36332 54280 94254 5993 56423 74251 88831 15708 70378 66124 65093 64633 65268 12454 3619 65729 98459 46036 22418 71156 90671 89164 30485 82556...
output:
7820956956
result:
ok 1 number(s): "7820956956"
Test #14:
score: 0
Accepted
time: 88ms
memory: 23084kb
input:
86872 92502 72102 39103 65076 82238 78982 58245 15670 12922 87254 3697 30139 26914 83682 72328 37465 8123 48044 65196 32489 50941 57925 67769 19139 58756 59368 49319 55649 70312 76805 50199 36294 69544 5107 39559 58716 99497 139 5684 21013 25490 18172 33270 64925 53415 40634 29265 5973 48623 29711 2...
output:
6805008535
result:
ok 1 number(s): "6805008535"
Test #15:
score: 0
Accepted
time: 40ms
memory: 26156kb
input:
65932 65933 47228 41749 40385 65744 35596 68752 3967 5645 61197 1212 24585 61150 29131 61942 89652 38952 53462 231 43665 46804 34360 50117 22667 11074 65538 64793 72029 55631 61358 17160 28162 9011 99423 9058 57885 84173 62029 39210 76856 62611 2767 94455 45718 32328 38449 31058 42332 29977 46801 52...
output:
3392885297
result:
ok 1 number(s): "3392885297"
Test #16:
score: 0
Accepted
time: 83ms
memory: 25252kb
input:
99894 113229 52097 79691 46817 1828 16289 95192 21018 57075 39240 76153 80384 96980 29832 31522 9830 9680 33935 4280 1772 3831 58516 28747 22812 65624 75996 69179 86710 29962 7107 35929 19304 55630 83746 73168 10346 99955 94622 6771 16560 89227 29132 85204 73127 63732 47238 11615 3777 46342 37948 67...
output:
8150047926
result:
ok 1 number(s): "8150047926"
Test #17:
score: 0
Accepted
time: 94ms
memory: 25980kb
input:
96899 110694 4260 74142 61968 38875 50178 39961 40927 82450 88704 11474 71617 64427 37561 64134 13462 51337 86372 93837 43255 37523 99149 93432 49495 96419 30391 4441 41463 33517 73609 69452 19140 89586 79880 66856 46828 93646 22690 13886 24800 61655 29946 99117 81457 23851 45507 26718 27768 62031 7...
output:
7957257870
result:
ok 1 number(s): "7957257870"
Test #18:
score: 0
Accepted
time: 85ms
memory: 27032kb
input:
90448 102873 18368 54233 75825 50704 15738 91609 56812 68389 7241 25130 70898 931 23231 40746 94625 33935 82001 28894 57814 30146 98608 19550 82230 87276 21951 17706 92563 74287 60846 55641 41687 11694 40019 78805 14746 13263 19387 57142 37676 46913 74182 11625 67042 88342 19657 58899 53567 7047 707...
output:
7382848524
result:
ok 1 number(s): "7382848524"
Test #19:
score: 0
Accepted
time: 66ms
memory: 22288kb
input:
99885 100161 57278 26432 98386 91636 9803 48483 29005 38016 91753 52261 77367 31864 15556 87516 50981 96087 99754 18367 68120 91245 4928 76 62183 27843 92357 36494 58380 19769 86952 1507 23950 61731 6148 11678 29600 10067 61954 60206 15281 8128 75259 38428 47607 91233 38988 56198 53548 11081 1741 10...
output:
7472130375
result:
ok 1 number(s): "7472130375"
Test #20:
score: 0
Accepted
time: 76ms
memory: 24844kb
input:
91180 91629 30744 73264 67809 16602 34643 46033 8323 62242 37581 50741 53419 2938 23675 12742 79395 958 66208 5848 74799 52509 9473 36527 73557 29871 884 18876 17627 5603 1842 9154 32015 80333 3797 24244 17914 78716 64821 85392 76596 60509 24932 57195 68092 24585 78004 38694 51233 44934 31234 62675 ...
output:
6850610282
result:
ok 1 number(s): "6850610282"
Test #21:
score: 0
Accepted
time: 69ms
memory: 23436kb
input:
87559 95242 25344 86167 24752 57170 46921 69614 64480 57312 1017 72939 71175 11639 22192 84280 57888 63915 54199 38595 27066 86071 86901 53803 39005 4166 29756 50497 14607 84509 68953 70150 85297 86375 70506 85111 8857 81929 13982 36883 46166 48659 42397 43209 26481 16778 33625 25673 4304 34998 2632...
output:
6982142626
result:
ok 1 number(s): "6982142626"
Test #22:
score: 0
Accepted
time: 55ms
memory: 20524kb
input:
81796 82570 74100 70678 32921 21335 24128 63185 32446 81119 50642 64042 37499 73000 50682 5651 84995 71503 25826 33355 27638 12109 96895 38705 26139 72871 32177 47832 25552 63715 21230 5613 20298 17652 97565 27660 48953 66012 56698 48034 48029 10324 63669 17099 76134 76573 83672 13550 44000 3111 193...
output:
6065406703
result:
ok 1 number(s): "6065406703"
Test #23:
score: 0
Accepted
time: 58ms
memory: 20688kb
input:
74936 76402 58295 37290 80798 57249 72730 89320 64841 69155 90367 48917 13767 48082 17218 57137 83377 15381 44354 43279 17635 40625 8436 45220 8761 79717 47803 70959 5816 10182 29206 60503 36136 51993 29263 1689 16429 47887 49703 9004 84093 29521 72660 71574 66028 28344 49850 51883 13195 15979 74469...
output:
5747807602
result:
ok 1 number(s): "5747807602"
Test #24:
score: 0
Accepted
time: 80ms
memory: 23960kb
input:
98499 101119 80883 22723 13332 32041 71010 79940 36162 70792 66807 51359 96474 18537 34186 33057 52943 91193 53385 97162 30060 85064 69428 83434 26356 33355 9874 59193 72040 89971 59342 16454 78697 96054 56090 56849 87816 59277 77966 31205 30 5874 79144 16697 81862 39594 27161 106 17964 42384 73912 ...
output:
7544417105
result:
ok 1 number(s): "7544417105"
Test #25:
score: 0
Accepted
time: 78ms
memory: 26628kb
input:
97365 103009 59524 21924 95897 81610 47430 88227 88328 36514 33099 57291 82177 63146 35114 79335 70499 17572 86644 28372 9168 33013 73062 80745 30020 38119 90980 93726 93371 60592 80567 76630 86302 44767 84518 39889 94369 62910 51858 74939 6483 61662 34000 32718 28470 86183 17813 80032 50274 78508 7...
output:
7588255830
result:
ok 1 number(s): "7588255830"
Test #26:
score: 0
Accepted
time: 71ms
memory: 23944kb
input:
97328 98147 81765 81622 98251 95058 22822 50016 75824 76938 79795 58133 27600 82684 38275 70273 68496 81228 91512 92789 63967 33042 11064 77721 54664 56380 40322 16793 94501 32301 63615 6066 29818 86484 91894 69281 64217 29534 95991 26634 9881 3308 2545 5204 57154 87594 54175 60548 39556 9105 25826 ...
output:
7265924265
result:
ok 1 number(s): "7265924265"
Test #27:
score: 0
Accepted
time: 86ms
memory: 20992kb
input:
96813 101397 41985 18433 19538 71071 35539 12589 2316 24472 22626 3522 2164 46227 32034 29331 24700 40196 10452 74885 10056 1011 26528 55451 55280 20883 67263 60900 94635 17850 86498 18981 47364 19532 76197 36170 73094 86106 87659 35682 8495 48305 14225 50285 77234 23605 58385 33735 64644 76242 8892...
output:
7508242013
result:
ok 1 number(s): "7508242013"
Test #28:
score: 0
Accepted
time: 59ms
memory: 22700kb
input:
77372 82115 48296 37013 92031 6602 43402 10333 43506 67080 13876 69081 57896 38219 28982 69921 1680 31709 35849 16743 19667 49081 55704 71596 58510 40316 52025 26806 4685 14699 353 57825 25793 10478 9424 57182 68802 95561 61967 29193 41567 71058 55780 23893 9815 19388 30590 38315 3715 42778 55506 68...
output:
6020824282
result:
ok 1 number(s): "6020824282"
Test #29:
score: 0
Accepted
time: 92ms
memory: 23324kb
input:
99045 106182 9425 15893 50838 16101 57279 22395 85297 37427 8014 23370 44581 41032 24155 65714 36549 18023 78105 12009 71149 62126 47304 20330 41195 21961 80893 91006 21243 41105 17717 45923 56843 71237 2156 31298 93618 27628 12375 9715 40541 30286 81666 10920 31994 33363 5817 60114 78988 82017 1147...
output:
7798152371
result:
ok 1 number(s): "7798152371"
Test #30:
score: 0
Accepted
time: 54ms
memory: 20228kb
input:
75922 79430 19791 587 15391 27840 8867 57348 9683 66380 36490 59955 70589 81686 15905 14254 38768 1132 19075 89550 69111 19542 51369 62054 37890 60244 36696 18613 181 17455 37201 96472 66315 56692 1636 68303 60216 37001 23145 73089 82886 14430 12450 51320 343 39865 97939 17575 35616 95745 8609 62861...
output:
5860923878
result:
ok 1 number(s): "5860923878"