ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#387 | #41. 「NOIP2010」关押罪犯 | j27eGU | 100 | 231ms | 4872kb | C++23 | 665b | 2025-04-23 11:35:41 | 2025-04-23 11:35:43 |
answer
#include<bits/stdc++.h>
using namespace std;
struct cri
{
int x,y,w;
}a[100005];
int n,m,f[100005];
bool cmp(cri x,cri y)
{
return x.w>y.w;
}
void init()
{
for(int i=1;i<=n<<1;i++)f[i]=i;
}
int find(int i)
{
if(f[i]==i)return i;
f[i]=find(f[i]);
return f[i];
}
void merge(int i,int j)
{
f[find(j)]=find(i);
}
int main()
{
scanf("%d%d",&n,&m);
init();
for(int i=1;i<=m;i++)scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].w);
sort(a+1,a+1+m,cmp);
for(int i=1;i<=m;i++)
{
int x=a[i].x,y=a[i].y;
if(find(x)==find(y))
{
printf("%d",a[i].w);
return 0;
}
merge(x,y+n);
merge(y,x+n);
}
cout<<0;
return 0;
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 1ms
memory: 3540kb
input:
2 1 1 2 28135
output:
0
result:
ok "0"
Test #2:
score: 10
Accepted
time: 3ms
memory: 3424kb
input:
10 30 3 4 1567 2 9 27269 2 3 13371 5 10 12983 2 7 10023 3 8 643 8 10 5710 1 8 15407 1 10 29087 2 6 2...
output:
27269
result:
ok "27269"
Test #3:
score: 10
Accepted
time: 1ms
memory: 3540kb
input:
15 60 7 14 5275 2 14 21363 1 12 29331 1 11 31214 6 14 727 10 14 10179 4 12 5273 1 8 25120 4 5 8931 3...
output:
25120
result:
ok "25120"
Test #4:
score: 10
Accepted
time: 2ms
memory: 3448kb
input:
100 3000 48 87 15855 76 89 3814 6 60 12964 1 37 13572 55 93 24022 48 56 9201 30 93 3593 67 89 15511 ...
output:
32162
result:
ok "32162"
Test #5:
score: 10
Accepted
time: 4ms
memory: 3520kb
input:
400 1000 121 397 15850 214 354 7375 40 86 15022 267 355 13170 184 373 810 4 233 8670 147 280 31371 2...
output:
27143
result:
ok "27143"
Test #6:
score: 10
Accepted
time: 12ms
memory: 3656kb
input:
1000 10000 506 557 30691 356 366 32760 756 957 28865 548 804 13844 123 818 7238 450 662 22807 159 38...
output:
31071
result:
ok "31071"
Test #7:
score: 10
Accepted
time: 31ms
memory: 4140kb
input:
2000 50000 1360 1790 7458 91 729 10397 303 1906 13697 1072 1440 2409 1312 1336 22220 1304 1388 20326...
output:
32067
result:
ok "32067"
Test #8:
score: 10
Accepted
time: 41ms
memory: 4352kb
input:
5000 50000 3592 4146 11109 895 4007 32337 4192 4964 11537 920 3451 7648 2549 4517 11747 690 4615 167...
output:
30953
result:
ok "30953"
Test #9:
score: 10
Accepted
time: 65ms
memory: 4788kb
input:
10000 100000 180 1910 2827 576 6842 20718 2231 7020 19683 8132 9333 18984 1357 1680 3713 4222 6864 1...
output:
31065
result:
ok "31065"
Test #10:
score: 10
Accepted
time: 71ms
memory: 4872kb
input:
20000 100000 5200 17411 22034 507 4572 24445 13866 14874 4882 304 9151 21478 3672 11317 31797 7132 1...
output:
29711
result:
ok "29711"