QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#818536 | #3561. Capital City | modwwe | 11 | 498ms | 297112kb | C++23 | 3.9kb | 2024-12-17 21:37:07 | 2024-12-17 21:37:07 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task2 "ftree"
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".out","w",stdout)
#define pb push_back
#define mask(k) (1<<k)
#define mp make_pair
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e14;
const ll mod2 = 1e9+7;
const int mod1 = 998244353;
const ll base=67;
int add(int x,int y)
{
if(x+y>=mod2) x-=mod2;
if(x+y<0)x+=mod2;
return x+y;
}
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,lim,w,l,r,ans ;
int kk;
int el = 19;
main()
{
if(fopen(task2".inp","r"))
{
fin(task2);
fou(task2);
}
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
//modwwe
phongbeo(),down
// checktime
}
int color[200001],st[18][200001],in[200001],depth[200001],ou[200001],low[200001],num[200001];
vector<int> v[4000001],ke[200001],lc[200001];
int id[18][200001];
bool cek[4000001],vis[200001];
void noi(int x,int y)
{
int par=color[x];
for(int i=0; i<18; i++)
if(bit(y,i))
{
v[par].pb(id[i][x]);
x=st[i][x];
}
}
bool check(int x,int y)
{
if(in[x]<=in[y]&&in[y]<=ou[x]) return 1;
return 0;
}
int lca(int x,int y)
{
if(check(x,y)) return x;
for(int i=17; i>=0; --i)
if(!check(st[i][x],y))
x=st[i][x];
return st[0][x];
}
void dfs(int x,int y)
{
in[x]=++dem;
st[0][x]=y;
depth[x]=depth[y]+1;
for(auto f:ke[x])
if(f^y)
dfs(f,x);
ou[x]=dem;
}
stack<int> s;
void dfs2(int x)
{
num[x]=low[x]=++dem;
s.push(x);
for(auto f:v[x])
{
if(num[f]==0) dfs2(f);
if(low[f]==inf)cek[x]=1;
low[x]=min(low[x],low[f]);
}
if(low[x]==num[x])
{
s2=-1;
s3=0;
bool de=0;
while(s2!=x)
{
s2=s.top();
s.pop();
low[s2]=inf;
if(s2<=k&&!vis[s2])
s3++,vis[s2]=1;
if(cek[s2])de=1;
}
if(!de)s4=min(s4,s3);
}
}
void phongbeo()
{
cin>>n>>k;
for(int i=1; i<n; i++)
cin>>l>>r,ke[l].pb(r),ke[r].pb(l);
for(int i=1; i<=n; i++)
cin>>color[i],id[0][i]=color[i],lc[color[i]].pb(i);
dfs(1,0);
ou[0]=n;
dem=k;
for(int i=1; i<18; i++)
for(int j=1; j<=n; j++)
{
id[i][j]=++dem;
v[id[i][j]].pb({id[i-1][j]});
v[id[i][j]].pb({id[i-1][st[i-1][j]]});
st[i][j]=st[i-1][st[i-1][j]];
}
for(int i=1; i<=k; i++)
{
int s=0;
for(auto x:lc[i])
{
if(s==0) s=x;
else s=lca(s,x);
}
for(auto x:lc[i])
noi(x,depth[x]-depth[s]+1);
}
s4=n+1;
dem=0;
for(int i=1; i<=k; i++)
if(!num[i])
dfs2(i);
cout<<s4-1;
}
详细
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 4ms
memory: 69164kb
input:
20 3 16 10 10 3 18 2 4 5 8 6 11 12 2 14 1 2 6 3 1 11 1 4 7 20 3 2 9 7 3 13 15 19 5 7 17 6 12 15 2 2 1 1 1 2 2 1 3 3 1 3 1 3 2 2 1 2 2 3
output:
2
result:
ok single line: '2'
Test #2:
score: 1
Accepted
time: 0ms
memory: 69124kb
input:
20 3 13 1 5 17 14 1 15 2 19 17 7 9 4 6 12 5 15 18 1 2 16 20 3 4 11 8 2 7 9 16 5 1 3 2 5 8 7 10 1 2 3 2 1 3 3 3 2 3 3 3 3 2 2 1 3 1 2 3
output:
2
result:
ok single line: '2'
Test #3:
score: 1
Accepted
time: 3ms
memory: 65244kb
input:
20 3 7 6 9 13 12 11 16 6 20 8 14 17 2 3 9 11 4 2 2 1 12 14 15 8 18 16 9 19 10 4 2 9 8 3 4 5 5 6 2 2 2 3 2 3 3 1 2 2 1 2 1 1 1 2 3 2 3 3
output:
2
result:
ok single line: '2'
Test #4:
score: 1
Accepted
time: 4ms
memory: 57048kb
input:
20 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 10 9 8 5 6 7 1 2 3 4 5 6 7 1 2 3 4 8 9 10
output:
6
result:
ok single line: '6'
Test #5:
score: 1
Accepted
time: 3ms
memory: 36496kb
input:
20 10 19 6 6 3 3 18 18 20 20 11 11 7 7 17 17 14 14 9 9 13 13 5 5 12 12 4 4 10 10 2 2 16 16 15 15 8 8 1 8 3 2 6 7 5 7 5 1 1 4 9 4 6 2 10 9 10 8 3
output:
4
result:
ok single line: '4'
Test #6:
score: 1
Accepted
time: 7ms
memory: 38744kb
input:
20 10 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 10 9 8 7 6 5 4 3 2 1 2 1 3 4 5 6 7 8 9 10
output:
1
result:
ok single line: '1'
Test #7:
score: 1
Accepted
time: 3ms
memory: 38552kb
input:
20 10 20 9 9 17 17 4 15 4 15 16 3 19 3 16 19 6 19 2 19 7 6 11 11 8 8 13 13 10 10 5 5 14 14 12 12 1 1 18 10 2 7 9 10 3 2 3 7 1 4 1 4 8 5 9 6 8 6 5
output:
1
result:
ok single line: '1'
Test #8:
score: 1
Accepted
time: 4ms
memory: 52824kb
input:
20 10 18 12 12 11 9 11 9 19 8 7 8 19 16 7 16 20 3 6 3 20 6 15 15 2 2 14 14 10 10 13 13 4 4 5 5 17 17 1 9 8 6 9 2 8 4 3 6 2 5 10 7 1 1 10 7 3 5 4
output:
1
result:
ok single line: '1'
Test #9:
score: 1
Accepted
time: 3ms
memory: 34424kb
input:
20 10 13 15 15 12 15 17 15 5 12 16 16 4 18 4 18 11 2 14 2 11 14 3 3 9 9 8 8 6 6 1 1 7 7 19 19 10 10 20 9 6 5 7 8 1 3 5 4 9 7 6 2 4 10 2 8 10 1 3
output:
1
result:
ok single line: '1'
Test #10:
score: 1
Accepted
time: 6ms
memory: 38488kb
input:
1 1 1
output:
0
result:
ok single line: '0'
Subtask #2:
score: 10
Accepted
Dependency #1:
100%
Accepted
Test #11:
score: 10
Accepted
time: 8ms
memory: 40980kb
input:
2000 250 1875 208 1788 262 675 397 779 1033 185 238 469 70 650 1600 146 1093 248 1604 167 504 914 1041 1263 1427 131 68 1759 81 114 170 676 923 489 95 1747 107 133 91 582 164 35 1315 592 740 888 475 1230 117 818 522 1108 52 1276 1891 4 1 212 1917 1298 662 642 391 7 5 1035 1804 856 656 119 99 385 355...
output:
244
result:
ok single line: '244'
Test #12:
score: 10
Accepted
time: 4ms
memory: 53172kb
input:
2000 250 37 10 1592 1517 607 125 77 194 56 1371 1470 1162 1004 323 309 567 925 188 389 509 1644 1619 286 1000 144 1539 244 900 644 28 528 26 251 140 183 81 764 248 21 775 191 25 1178 819 29 94 1166 934 271 1066 3 27 316 1063 901 91 219 64 853 983 13 5 180 70 394 992 1537 1193 188 1557 618 1613 116 7...
output:
246
result:
ok single line: '246'
Test #13:
score: 10
Accepted
time: 3ms
memory: 36860kb
input:
2000 250 1155 1655 183 259 19 685 845 610 1139 1514 665 549 199 272 516 1425 510 499 721 1497 316 497 452 1417 136 379 12 10 99 281 1850 1671 275 356 786 306 108 1833 1216 238 1914 210 1908 1158 771 893 41 635 67 988 202 726 16 55 671 577 199 306 731 1723 281 293 115 106 1365 374 1239 658 106 194 47...
output:
245
result:
ok single line: '245'
Test #14:
score: 10
Accepted
time: 9ms
memory: 36892kb
input:
2000 250 1580 249 640 178 2 1 615 1054 112 816 949 22 57 793 407 950 865 416 1903 1229 975 365 455 1355 1494 98 1565 497 1244 780 1323 1074 1588 138 1503 1145 447 352 1264 1880 951 1564 821 393 232 569 1023 572 158 255 571 1257 1693 704 1816 309 726 255 570 528 284 471 1430 569 26 1408 357 1902 452 ...
output:
245
result:
ok single line: '245'
Test #15:
score: 10
Accepted
time: 9ms
memory: 37364kb
input:
2000 758 1645 394 394 842 842 1368 1368 89 89 805 805 351 351 811 811 1752 1752 1787 1787 1219 1219 1299 1299 822 822 878 878 1582 1582 807 807 1371 1371 1142 1645 924 1645 282 282 834 282 74 74 1744 74 1834 1834 1309 1834 1009 1009 870 1009 1163 1163 1879 1163 25 25 1967 25 1779 1779 1974 1779 268 ...
output:
7
result:
ok single line: '7'
Test #16:
score: 10
Accepted
time: 4ms
memory: 41204kb
input:
2000 884 178 1218 1218 1351 1351 1815 1815 98 98 343 343 1095 1095 862 862 719 719 1071 1071 1231 1231 1366 1366 72 72 816 178 1470 178 1696 1696 298 1696 1448 1448 1172 1448 1006 1006 514 1006 647 647 544 647 1707 1707 872 1707 563 563 1049 563 1428 1428 665 1428 716 716 734 716 1195 1195 935 1195 ...
output:
6
result:
ok single line: '6'
Test #17:
score: 10
Accepted
time: 4ms
memory: 37164kb
input:
2000 503 32 1635 1635 1645 1645 557 557 40 40 126 126 1165 1165 888 888 567 567 913 913 702 702 1242 1242 1385 1385 12 12 1224 1224 1688 1688 1189 1189 620 620 1778 1778 989 989 1914 1914 727 727 17 17 921 921 728 728 1601 1601 941 941 29 29 1692 1692 945 945 815 815 757 757 1413 1413 1539 1539 161 ...
output:
1
result:
ok single line: '1'
Test #18:
score: 10
Accepted
time: 4ms
memory: 41132kb
input:
2000 505 393 839 839 134 134 1135 1135 288 288 1769 1769 1658 1658 147 147 523 523 276 276 779 779 263 263 1152 1152 1858 1858 1556 1556 1353 1353 1724 1724 1951 1951 1903 1903 1761 1761 1775 1775 122 122 355 355 43 43 368 368 300 300 175 175 947 947 1239 1239 1653 1653 373 373 1448 1448 1621 1621 7...
output:
3
result:
ok single line: '3'
Test #19:
score: 10
Accepted
time: 4ms
memory: 36956kb
input:
2000 511 16 767 767 1917 1917 555 555 815 815 629 629 211 211 101 101 128 128 543 543 1548 1548 1909 1909 958 958 841 841 43 43 910 910 881 881 148 148 1263 1263 1117 1117 1710 1710 1860 1860 1395 1395 1 1 1740 1740 107 107 1717 1717 1553 1553 1397 1397 552 552 1355 1355 1569 1569 567 567 1265 1265 ...
output:
9
result:
ok single line: '9'
Test #20:
score: 10
Accepted
time: 10ms
memory: 41240kb
input:
2000 503 788 1186 1186 1179 1179 1230 1230 1639 1639 838 838 522 522 227 227 1293 1293 1710 1710 1976 1976 558 558 1559 1559 1167 1167 1429 1429 733 733 346 346 1476 1476 220 220 764 764 898 898 790 790 1868 1868 90 90 271 271 787 787 294 294 1087 1087 215 215 342 342 636 636 350 350 646 646 1335 13...
output:
1
result:
ok single line: '1'
Test #21:
score: 10
Accepted
time: 8ms
memory: 37420kb
input:
2000 506 1456 192 192 699 699 1473 1473 101 101 1798 1798 1708 1708 1185 1185 1850 1850 961 961 471 471 1866 1866 662 662 562 562 88 88 831 831 601 601 893 893 860 860 1951 1951 362 362 434 434 1879 1879 255 255 304 304 1181 1181 957 957 213 213 1902 1902 173 173 743 743 417 417 48 48 1262 1262 1121...
output:
4
result:
ok single line: '4'
Test #22:
score: 10
Accepted
time: 8ms
memory: 37200kb
input:
2000 1000 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 52 5...
output:
3
result:
ok single line: '3'
Test #23:
score: 10
Accepted
time: 8ms
memory: 37124kb
input:
2000 961 396 15 15 401 401 1074 1074 1431 1431 775 775 428 428 278 278 1762 1762 402 402 156 156 1303 1303 1897 1897 460 460 212 212 165 165 318 318 1094 1094 1865 1865 977 977 588 588 580 580 41 41 1127 1127 1010 1010 1035 1035 1319 1319 1078 1078 1059 1059 1210 1210 518 518 1077 1077 79 79 556 556...
output:
10
result:
ok single line: '10'
Test #24:
score: 10
Accepted
time: 10ms
memory: 40964kb
input:
2000 999 1747 1211 1211 1085 1085 1457 1457 1761 1761 420 420 565 565 1624 1624 1920 1920 1859 1859 1924 1924 1572 1572 1092 1092 1642 1642 218 218 1728 1728 417 417 603 603 145 145 374 1747 1243 1747 903 1243 658 1243 1180 658 1552 658 245 1552 148 1552 228 148 1498 148 1168 1498 1599 1498 1578 159...
output:
9
result:
ok single line: '9'
Test #25:
score: 10
Accepted
time: 10ms
memory: 37204kb
input:
2000 526 1376 1751 1751 1728 1728 145 1987 145 1987 517 1864 557 1864 517 557 718 112 718 112 1859 1703 1859 1703 1193 726 1193 726 1031 34 443 34 1031 1662 941 1662 1855 379 643 379 1018 769 491 769 643 348 491 348 366 1909 453 1909 366 116 453 116 581 1270 94 1270 581 94 1351 1351 1139 1934 1863 1...
output:
7
result:
ok single line: '7'
Test #26:
score: 10
Accepted
time: 8ms
memory: 55452kb
input:
2000 508 100 1383 1383 82 82 676 1055 676 1055 974 1105 1776 1105 974 1776 571 571 84 1856 84 1856 932 678 1805 678 27 1093 347 1093 354 651 520 651 68 1165 733 1165 68 733 621 1313 1404 1313 1936 1231 766 1231 1297 766 1815 1815 323 323 1434 1628 1434 1628 753 1205 124 1205 1523 272 1516 272 1186 5...
output:
1
result:
ok single line: '1'
Test #27:
score: 10
Accepted
time: 4ms
memory: 41216kb
input:
2000 528 398 366 128 1316 128 320 838 18 838 1755 18 411 537 411 537 740 1869 740 1869 750 1096 750 1096 863 321 597 321 926 877 1892 877 564 1835 1197 1835 186 573 1810 573 1197 1810 25 25 292 675 1730 675 257 624 1218 624 886 1448 1326 1448 1469 1384 410 1384 1469 410 785 785 1555 610 1555 610 548...
output:
7
result:
ok single line: '7'
Test #28:
score: 10
Accepted
time: 4ms
memory: 61720kb
input:
2000 511 997 1974 997 472 1974 900 1974 285 1974 309 900 475 900 1254 900 383 475 1500 475 1948 1500 1080 1080 26 26 1656 1656 213 1656 1978 213 447 213 956 213 1278 447 1175 447 651 447 1797 447 1245 1175 1515 1175 72 1515 1892 1515 957 1515 567 1892 1319 1319 1130 1990 1130 1990 186 1650 64 1650 1...
output:
2
result:
ok single line: '2'
Test #29:
score: 10
Accepted
time: 8ms
memory: 55296kb
input:
2000 520 1361 533 1361 1936 533 984 984 156 1580 156 1580 924 1986 812 1986 924 812 988 988 1309 988 1450 988 1062 1309 1845 1845 1625 1625 297 1625 1970 1625 1711 297 1372 297 333 1372 1546 619 1546 619 1029 24 1029 24 1512 24 1539 627 302 627 965 850 1388 850 1789 1719 1213 1719 1789 1719 1777 172...
output:
5
result:
ok single line: '5'
Test #30:
score: 10
Accepted
time: 9ms
memory: 37428kb
input:
2000 509 1760 737 1760 1465 1760 376 1760 1433 737 1269 737 1204 1269 1106 1269 1326 1269 1081 1106 255 895 255 895 1983 1496 48 1496 1361 1496 186 1518 1959 1518 1361 1959 1585 1585 218 218 1980 1980 568 568 1004 1004 663 1643 1511 1643 663 1643 838 1209 1336 1209 838 278 1336 278 1847 1830 1652 18...
output:
0
result:
ok single line: '0'
Subtask #3:
score: 0
Wrong Answer
Test #31:
score: 0
Wrong Answer
time: 498ms
memory: 297112kb
input:
200000 100000 185785 19011 19011 181550 181550 117972 117972 192238 192238 137685 137685 10126 10126 193657 193657 130856 130856 119980 119980 37122 37122 24497 24497 162102 162102 104298 104298 61332 61332 103789 103789 71060 71060 54044 54044 12075 12075 55296 55296 70106 70106 27512 27512 190160 ...
output:
-1
result:
wrong answer 1st lines differ - expected: '4', found: '-1'
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%