QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#308345 | #4795. Taxi | KLPP# | AC ✓ | 107ms | 56832kb | C++20 | 2.8kb | 2024-01-19 23:08:29 | 2024-01-19 23:08:30 |
Judging History
answer
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef long long int lld;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)
vector<pair<int,lld> > nei[1000000];
int sz[1000000];
bool visited[1000000];
vector<pair<lld,lld> >V;
lld tot[1000000];
const lld INF=1e18;
const lld MOD=1e9+7;
const int MAX=3'000'000;
lld fact[MAX];
lld inv[MAX];
lld ModPow(lld base, lld exp){
if(exp==0)return 1;
if(exp%2==1)return (base*ModPow(base,exp-1))%MOD;
lld a=ModPow(base,exp/2);
return (a*a)%MOD;
}
lld comb(int a, int b){
if(b<0 || b>a)return 0;
lld ans=fact[a];
ans*=inv[b];
ans%=MOD;
ans*=inv[a-b];
ans%=MOD;
return ans;
}
lld GCD(lld a, lld b){
if(b==0)return a;
return GCD(b,a%b);
}
const int Mx2=6000;
lld prd[Mx2];
int n;
void DFS(int node){
visited[node]=true;
sz[node]=1;
trav(a,nei[node]){
if(!visited[a.first]){
DFS(a.first);
tot[min(sz[a.first],n-sz[a.first])]+=a.second;
sz[node]+=sz[a.first];
}
}
}
void solve(){
int m;
cin>>n>>m;
rep(i,0,n-1){
int x,y;
lld l;
cin>>x>>y>>l;
x--;y--;
nei[x].push_back({y,l});
nei[y].push_back({x,l});
}
rep(i,0,n+1)tot[i]=0;
DFS(0);
lld ans=0;
rep(i,1,n){
lld conj=n-i;
lld can=1;
lld tot2=0;
lld S=i*ModPow(conj,MOD-2);
S%=MOD;
lld CurPow=ModPow(conj,2*m);
rep(c,0,2*m+1){
lld par=min(c,2*m-c);
lld tot3=CurPow;
tot3%=MOD;
tot3*=comb(2*m,c);
tot3%=MOD;
CurPow*=S;
CurPow%=MOD;
//~ rep(a,0,c+1){
//~ lld b=c-a;
//~ if(0<=a && a<=m && 0<=b && b<=m){
//~ }else continue;
//~ lld par2=ModPow(i,a)*ModPow(i,b);
//~ par2%=MOD;
//~ par2*=ModPow(conj,m-a);
//~ par2%=MOD;
//~ par2*=comb(m,a);
//~ par2%=MOD;
//~ par2*=ModPow(conj,m-b);
//~ par2%=MOD;
//~ par2*=comb(m,b);
//~ par2%=MOD;
//~ tot3+=par2;
//~ tot3%=MOD;
//~ }
//cout<<tot3<<" A "<<c<<" "<<i<<endl;
tot2+=tot3*par;
tot2%=MOD;
}
//cout<<i<<" "<<tot2<<"\n";
can*=tot2;
can%=MOD;
ans+=can*tot[i];
ans%=MOD;
}
cout<<ans<<"\n";
}
int main(){
fact[0]=1;
rep(i,1,MAX)fact[i]=(i*fact[i-1])%MOD;
inv[MAX-1]=ModPow(fact[MAX-1],MOD-2);
for(int i=MAX-2;i>-1;i--)inv[i]=((i+1)*inv[i+1])%MOD;
//~ rep(i,0,Mx2){
//~ rep(j,0,Mx2){
//~ if(j==0)Q[i][j]=1;
//~ else{
//~ if(i==0)Q[i][j]=0;
//~ else{
//~ Q[i][j]=(Q[i-1][j]+j*Q[i][j-1]);
//~ Q[i][j]%=MOD;
//~ }
//~ }
//~ Q[i][j]=ModPow(i,j)*(j+1);
//~ Q[i][j]%=MOD;
//~ }
//~ }
ios::sync_with_stdio(0);
cin.tie(0);
int tt=1;
//cin>>tt;
while(tt--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 99ms
memory: 55272kb
input:
2500 2500 531 1977 7285 705 44 4544 1409 2220 8896 2175 2086 9343 1947 729 2482 1114 1832 186 2388 1775 9841 1028 2097 7734 1949 2130 1115 407 1801 352 1165 254 8847 625 844 9853 551 1980 457 1683 163 7785 864 2338 1532 1214 1578 2055 387 1525 797 2070 1976 910 248 568 1444 2434 509 7641 2100 1779 6...
output:
796272069
result:
ok 1 number(s): "796272069"
Test #2:
score: 0
Accepted
time: 93ms
memory: 56784kb
input:
2500 2500 2197 1252 7783 1344 1657 7880 354 952 8879 198 1840 820 1670 89 6814 931 1957 770 1629 1704 5668 1185 2264 1012 2429 1406 1478 1039 858 5411 363 430 2690 159 2155 2278 908 65 4608 867 955 3036 530 921 8958 1463 888 192 2059 2 3860 2045 1325 7513 1203 895 8310 853 1039 1229 1132 222 1274 20...
output:
800277337
result:
ok 1 number(s): "800277337"
Test #3:
score: 0
Accepted
time: 99ms
memory: 53460kb
input:
2500 2500 680 1473 8535 1796 255 283 1693 1500 1563 1499 2196 9824 371 1896 8832 899 1757 9220 1624 2246 1029 1081 195 1002 2409 1418 7220 1079 1571 7057 1846 2257 2286 259 739 9842 449 1797 4290 1457 1609 8548 803 184 7605 17 2427 2456 588 324 6053 1845 2070 8862 2470 1778 405 365 1239 207 2299 806...
output:
547423329
result:
ok 1 number(s): "547423329"
Test #4:
score: 0
Accepted
time: 99ms
memory: 53436kb
input:
2500 2500 2396 178 3393 1853 1929 9572 313 1131 5954 467 393 6703 1262 149 7649 413 188 2284 2440 78 2585 501 1455 8427 1732 1009 471 646 1166 6841 461 546 3041 260 1156 9895 1658 685 2147 1756 1586 1971 1391 1031 4825 393 1127 8531 1631 2298 4524 2013 2439 1605 1667 1798 6004 1151 1367 7802 492 636...
output:
77917670
result:
ok 1 number(s): "77917670"
Test #5:
score: 0
Accepted
time: 107ms
memory: 55284kb
input:
2500 2500 622 872 9352 1092 1457 3889 1185 1229 1226 1938 496 2648 919 1468 5623 1509 2194 7049 738 1899 1603 2198 1391 6246 456 35 8853 1602 2198 4136 2394 1979 99 169 2350 1205 169 1929 8276 1319 460 2451 733 963 5694 1252 247 3035 327 1342 6659 2023 2302 464 676 172 4142 370 1932 3622 2108 1562 9...
output:
966633979
result:
ok 1 number(s): "966633979"
Test #6:
score: 0
Accepted
time: 93ms
memory: 56712kb
input:
2500 2500 350 2048 188 1319 1636 5675 2127 363 4610 1142 1496 5091 135 1840 1570 2129 859 6286 569 681 4114 945 1687 8259 2207 2346 7210 1124 690 9970 972 1973 2622 1989 2086 6038 479 1655 1051 1002 1968 2534 1539 7 1286 98 2321 9876 845 1731 5896 1254 706 8598 661 718 8514 984 875 8151 899 2404 396...
output:
888921072
result:
ok 1 number(s): "888921072"
Test #7:
score: 0
Accepted
time: 107ms
memory: 53364kb
input:
2500 2500 2011 1204 8639 358 2492 5672 807 1582 7092 456 580 9850 365 1565 7257 1106 1060 3750 1491 1957 5729 1508 2386 8865 1267 90 4675 1923 1265 1638 1734 133 5562 1296 496 3155 660 1016 2109 930 1464 4392 2408 1086 3793 1377 1147 7809 1489 1176 7627 929 743 6230 697 1102 2859 1789 2397 9796 1880...
output:
417477843
result:
ok 1 number(s): "417477843"
Test #8:
score: 0
Accepted
time: 107ms
memory: 53800kb
input:
2500 2500 596 1843 4299 1674 2401 6627 1968 636 6879 1465 1724 2764 1280 961 7350 1231 863 7180 1495 2480 5755 1450 1540 9108 1700 1539 2821 1338 228 375 371 564 5670 1991 227 4171 242 1038 6842 1569 1435 7595 2139 1273 9442 450 1272 3538 1791 1337 3136 1859 2389 9589 809 218 1501 2042 766 1356 1838...
output:
131201714
result:
ok 1 number(s): "131201714"
Test #9:
score: 0
Accepted
time: 95ms
memory: 53652kb
input:
2500 2500 494 1836 4974 1603 1073 1174 1862 2023 6037 2251 1380 5436 152 109 9829 1411 2185 9428 946 1997 2 395 1648 5740 314 1426 8486 1107 2294 9057 731 2092 5481 618 1601 2022 1446 1107 2701 1307 1052 9782 932 2489 2239 2131 1739 177 2349 2494 1140 295 2275 4066 492 4 4776 2494 445 4865 1471 2342...
output:
98303712
result:
ok 1 number(s): "98303712"
Test #10:
score: 0
Accepted
time: 99ms
memory: 53600kb
input:
2500 2500 1508 120 7220 2071 1071 5350 224 931 4068 202 201 2929 2100 1524 5945 878 539 7918 211 1447 1295 1893 326 5841 938 2253 2451 883 1175 5244 580 34 6623 862 1312 868 488 2012 3984 1560 1512 5119 1659 2006 9669 2456 859 650 2275 666 9098 2144 235 5981 1430 246 5524 239 268 5171 247 1009 4589 ...
output:
81612896
result:
ok 1 number(s): "81612896"
Test #11:
score: 0
Accepted
time: 96ms
memory: 56740kb
input:
2500 2500 2465 1266 3813 101 470 9335 1507 987 8435 523 1808 344 579 1880 8985 233 831 8185 1730 1401 3684 2065 333 2028 2247 2123 1558 2282 2155 6346 1437 892 44 134 636 9665 2014 433 3635 1837 476 1536 1480 100 1071 1354 1247 6422 1081 268 4897 450 755 7571 725 2153 5878 840 1370 4079 1742 1586 87...
output:
558615417
result:
ok 1 number(s): "558615417"
Test #12:
score: 0
Accepted
time: 103ms
memory: 54124kb
input:
2500 2500 1279 1915 2860 1507 1056 3460 917 746 3648 297 20 2442 2380 1508 9506 361 742 1325 1263 1621 3196 1912 1275 6585 1484 1115 2182 1917 2252 3652 1314 355 3511 1406 685 2694 1832 385 8521 1277 1444 6421 511 619 3211 500 1318 9279 237 25 3015 2260 636 9144 278 153 9825 1156 2348 2175 1596 2040...
output:
520229776
result:
ok 1 number(s): "520229776"
Test #13:
score: 0
Accepted
time: 104ms
memory: 54860kb
input:
2500 2500 1086 1221 4975 1940 559 514 307 743 2730 151 1065 8863 1121 954 9899 724 173 932 2416 2241 7806 2107 1634 6276 2148 2041 5171 1477 1470 3470 2010 1484 3876 541 1273 980 2292 76 9467 467 769 4428 915 1297 9217 127 164 7037 1387 1890 9248 1075 581 6628 90 2067 8841 47 982 4265 106 2119 5807 ...
output:
722763012
result:
ok 1 number(s): "722763012"
Test #14:
score: 0
Accepted
time: 104ms
memory: 56824kb
input:
2500 2500 2499 88 4159 2185 1752 3065 1369 687 9522 2133 550 8205 713 1648 1299 66 1105 8418 2035 1810 195 548 745 6333 285 1731 2168 502 1909 7017 1415 660 9416 625 388 5415 1146 766 6848 1934 2168 812 776 2367 3079 2098 693 8670 1085 1067 5233 1903 279 2843 595 2313 652 2414 47 4620 564 867 6416 4...
output:
380863968
result:
ok 1 number(s): "380863968"
Test #15:
score: 0
Accepted
time: 103ms
memory: 54064kb
input:
2500 2500 83 1909 7855 479 983 1045 37 583 2917 693 2376 6469 573 582 909 1782 2448 7926 432 25 2485 232 233 4223 1527 2447 1340 2492 2185 2249 634 1086 3887 1245 2211 9768 1322 1446 1804 69 1792 894 1025 324 3341 2094 712 6063 1612 865 9217 2348 2264 6657 1444 2202 8840 1735 1205 593 845 652 9596 1...
output:
131189357
result:
ok 1 number(s): "131189357"
Test #16:
score: 0
Accepted
time: 99ms
memory: 55388kb
input:
2500 2500 1635 104 5097 1474 779 6886 257 687 867 107 838 1930 1308 897 1755 2418 1514 4849 1968 1256 3970 2376 292 9872 1841 2430 9491 583 2064 6005 1434 2051 2934 1464 9 4535 624 649 7719 2047 935 1770 970 1528 6004 2174 913 6852 2193 1606 8613 2314 1349 9504 1443 1684 4088 73 230 1085 998 2201 76...
output:
729645938
result:
ok 1 number(s): "729645938"
Test #17:
score: 0
Accepted
time: 107ms
memory: 55040kb
input:
2500 2500 2473 2378 2112 1470 1322 2208 155 2376 1254 2364 977 7691 655 272 9872 2384 431 8798 1156 1755 2329 2408 1444 6593 681 2095 223 1830 2022 3936 1287 1785 4506 479 1757 1084 1792 1024 5266 2015 2250 2179 845 101 1679 644 1737 1665 1147 1853 3264 74 229 9265 607 1793 3770 1309 560 5381 433 10...
output:
531387013
result:
ok 1 number(s): "531387013"
Test #18:
score: 0
Accepted
time: 104ms
memory: 54824kb
input:
2500 2500 1179 1194 1402 321 2116 8985 1257 2177 3041 433 2320 864 589 2350 10 2383 1051 7775 2470 536 6751 1161 148 1588 556 288 1599 2269 1506 2610 1273 1726 5812 1113 76 682 368 556 1182 1477 133 9592 505 8 1918 1856 2235 4996 1569 1222 3599 1628 1126 601 1485 1318 1507 1326 1774 421 942 2353 708...
output:
487261797
result:
ok 1 number(s): "487261797"
Test #19:
score: 0
Accepted
time: 99ms
memory: 55176kb
input:
2500 2500 1116 949 8627 1920 2303 9357 1780 1030 3989 914 715 4500 2277 1604 5733 708 249 3202 742 1130 6420 1551 852 9174 1656 1056 8420 311 1804 6565 1618 1549 9823 2169 595 3860 1612 1270 6466 1900 2119 7375 901 2027 7043 1644 1407 8300 1520 79 5387 854 1812 7448 166 1028 1425 132 679 6739 1225 7...
output:
61824570
result:
ok 1 number(s): "61824570"
Test #20:
score: 0
Accepted
time: 103ms
memory: 55420kb
input:
2500 2500 2156 852 973 2079 2238 6812 1206 2241 2825 688 2316 8430 1952 17 8771 1384 791 6742 1028 314 1330 1067 1653 1437 403 719 7549 2306 2157 4322 1018 2141 634 2329 335 5101 2217 2175 6351 747 225 2147 62 2318 2170 1983 1782 8362 1661 1604 792 1342 2050 7626 260 2258 2421 492 1860 2975 166 507 ...
output:
132570544
result:
ok 1 number(s): "132570544"
Test #21:
score: 0
Accepted
time: 105ms
memory: 55268kb
input:
2500 2500 128 1893 5891 519 1968 7272 2273 1586 8382 864 2404 2336 831 82 2290 964 490 2025 411 1259 3450 631 2387 3987 1983 172 9888 481 1552 898 447 380 920 1733 1243 9022 2330 2192 7474 2474 905 2378 1520 2419 1969 2151 136 4342 241 784 1716 2061 1659 3251 2414 139 9030 779 1444 9578 78 1754 5908...
output:
558191946
result:
ok 1 number(s): "558191946"
Test #22:
score: 0
Accepted
time: 103ms
memory: 53496kb
input:
2500 2500 623 113 7208 35 1550 4169 2219 1423 2978 384 1648 5042 973 1436 9703 863 156 3348 1343 1633 5885 267 1592 4304 526 1209 9153 1515 1143 756 107 490 8076 1134 2212 836 2338 642 8107 1156 74 9088 2087 211 170 366 1703 2171 1721 1841 5027 345 658 5691 1245 784 8197 413 1580 5176 227 1004 7087 ...
output:
136407841
result:
ok 1 number(s): "136407841"
Test #23:
score: 0
Accepted
time: 100ms
memory: 55324kb
input:
2500 2500 856 2213 1070 129 1048 2799 2178 1664 8275 414 1939 4291 1872 1555 4583 721 488 3491 943 2199 8516 94 1891 864 472 1311 5565 1259 128 7020 2187 828 2802 27 1965 287 1110 1266 6420 1833 2246 1987 1348 441 7066 2180 1227 6941 2410 383 8100 1983 1022 8482 1077 2225 4823 2046 2012 8452 1014 77...
output:
291183996
result:
ok 1 number(s): "291183996"
Test #24:
score: 0
Accepted
time: 103ms
memory: 53804kb
input:
2500 2500 1085 90 9020 1668 321 1254 1098 1789 4501 1841 1933 8745 4 119 342 104 1631 5062 783 921 4551 2342 2371 2710 1373 2411 6453 2006 189 7148 1535 195 1899 2014 1895 6219 772 446 2020 937 745 4581 526 2145 8934 285 1086 53 624 2375 7920 1915 185 374 1885 2025 2312 619 1296 3832 1313 1043 7981 ...
output:
261999086
result:
ok 1 number(s): "261999086"
Test #25:
score: 0
Accepted
time: 96ms
memory: 54340kb
input:
2500 2500 2274 1040 7928 358 947 235 992 2302 4387 2195 2252 2049 473 492 6467 808 715 2498 552 160 7062 2220 2429 103 1647 175 7513 470 298 3719 644 1459 8105 330 885 1539 1972 1551 690 2487 2251 9572 1344 2437 3253 479 1645 7867 103 2160 1377 446 27 7644 644 2273 9811 1438 1625 9137 424 53 2145 13...
output:
476957512
result:
ok 1 number(s): "476957512"
Test #26:
score: 0
Accepted
time: 103ms
memory: 53756kb
input:
2500 2500 712 691 9831 160 212 1432 2017 2056 146 2321 863 2052 712 344 5874 1937 1848 4222 1426 2201 7822 1721 1669 3995 837 1697 728 1126 1095 4822 2019 197 7403 1293 1103 7518 809 114 6122 1730 2488 9992 598 1897 3370 461 2225 3318 1322 695 2667 282 1709 5393 1108 62 5997 1210 104 8822 1482 249 5...
output:
54938458
result:
ok 1 number(s): "54938458"
Test #27:
score: 0
Accepted
time: 104ms
memory: 56832kb
input:
2500 2500 2455 1662 5325 1453 949 6574 918 628 338 806 757 8838 259 2358 8665 31 213 7648 72 2265 1661 1407 1776 5414 2229 2273 6518 1964 602 7176 898 1870 7297 907 659 2370 2363 1332 1816 664 2340 6900 16 2049 607 2028 1214 8057 2077 2192 2593 1377 275 5764 232 1010 5823 1559 927 2447 1010 886 5867...
output:
657455231
result:
ok 1 number(s): "657455231"
Test #28:
score: 0
Accepted
time: 95ms
memory: 53696kb
input:
2500 2500 2112 325 9175 1789 1145 1233 665 398 4996 1873 44 7200 952 418 6358 709 422 6840 1831 1941 9084 525 763 6960 1780 464 1430 1874 1458 8434 63 1637 6194 1208 1006 3319 245 667 4987 1973 1305 8391 62 2248 5326 122 2141 611 1414 1309 4269 2485 1382 818 1295 2042 9391 1797 302 6769 1304 35 5117...
output:
44898116
result:
ok 1 number(s): "44898116"
Test #29:
score: 0
Accepted
time: 95ms
memory: 54136kb
input:
2500 2500 122 2451 1790 2232 1554 2194 318 1901 7669 857 317 4763 2226 734 6970 1573 670 4371 1653 1530 4888 2192 1403 1957 712 1696 7676 134 1761 5419 896 722 151 1252 2355 585 1805 2165 6341 1928 1436 3400 1106 1295 2185 1927 1678 4043 2389 98 1316 1997 139 2551 1737 1144 9979 787 1422 3392 1983 1...
output:
505272473
result:
ok 1 number(s): "505272473"
Test #30:
score: 0
Accepted
time: 107ms
memory: 55184kb
input:
2500 2500 905 1954 4357 198 1105 7861 823 1790 7594 662 1018 1884 1298 1326 3704 2462 791 7082 1356 741 803 1434 320 679 830 1689 5998 254 1528 2684 402 573 198 5 1003 9208 390 2477 6706 2141 26 8408 1851 2489 6032 1879 323 9950 509 273 6170 2224 2164 4729 1668 2219 7863 114 2459 5012 1397 774 333 1...
output:
497766588
result:
ok 1 number(s): "497766588"
Test #31:
score: 0
Accepted
time: 106ms
memory: 55092kb
input:
2500 2500 2231 1319 6403 1172 1319 1995 1861 1319 7670 111 1319 7740 1614 1319 7311 1741 1319 2168 1162 1319 3081 1 1319 7486 645 1319 8366 541 1319 1132 1609 1319 7609 2003 1319 5321 357 1319 8751 1610 1319 429 1017 1319 7011 592 1319 8968 1390 1319 6116 2224 1319 6204 760 1319 1391 2264 1319 8694 ...
output:
982947476
result:
ok 1 number(s): "982947476"