QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#108774 | #6402. MEXimum Spanning Tree | cmdgbb | TL | 5ms | 7240kb | C++14 | 2.0kb | 2023-05-26 17:13:35 | 2023-05-26 17:13:39 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
int n,m;
const int M=1010;
int v[M];
int head[M],Next[M*2],ver[M*2],tot;
int h[M],N[M],x1[M],x2[M],t,edge[M];
int fa[M];
int qian[M];
int L[M][M];
queue<int> q;
void add(int x,int y,int z)
{
ver[++tot]=y;
Next[tot]=head[x];
head[x]=tot;
L[x][y]=z;
}
int add2(int x,int y,int z)
{
t++;
x1[t]=x;
x2[t]=y;
N[t]=h[z];
h[z]=t;
edge[t]=z;
return t;
}
int cj(int x)
{
if(x==fa[x])return x;
return fa[x]=cj(fa[x]);
}
void bj(int x,int y)
{
fa[cj(x)]=fa[cj(y)];
}
int chahuan(int x,int mb)
{
for(int i=head[x];i;i=Next[i])
{
int y=ver[i];
if(cj(x)!=cj(y)||qian[x]==y)continue;
qian[y]=x;
if(y==mb)return -1;
if(chahuan(y,mb)==-1)return -1;
}
}
void qk()
{
memset(v,0,sizeof(v));
while(q.size())q.pop();
}
bool js(int x)
{
for(int i=h[x];i;i=N[i])
{
int x=x1[i],y=x2[i];
if(cj(x)!=cj(y))
{
bj(x,y);
return true;
}
memset(qian,0,sizeof(qian));
chahuan(x,y);
for(int j=y;j!=x;j=qian[j])
{
int num=L[j][qian[j]];
if(v[num])continue;
q.push(num);
v[num]=1;
}
while(q.size())
{
int num=q.front();
q.pop();
if(js(edge[num]))return true;
}
}
return false;
}
void ds()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
int x,y,z;
scanf("%d%d%d",&x,&y,&z);
z=add2(x,y,z);
add(x,y,z);
add(y,x,z);
}
}
int ans()
{
for(int i=0;i<=m;i++)
{
qk();
if(js(i))continue;
else return i;
}
}
void csh()
{
for(int i=0;i<=n;i++)fa[i]=i;
}
int main()
{
ds();
csh();
cout<<ans();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3636kb
input:
4 4 1 2 0 2 3 1 1 3 1 3 4 2
output:
3
result:
ok 1 number(s): "3"
Test #2:
score: 0
Accepted
time: 5ms
memory: 7240kb
input:
1000 1000 647 790 6 91 461 435 90 72 74 403 81 240 893 925 395 817 345 136 88 71 821 831 962 53 164 270 298 14 550 317 99 580 81 26 477 488 977 474 861 413 483 167 872 675 17 819 327 449 594 242 68 381 983 319 867 582 358 869 225 669 274 352 392 40 388 998 246 477 44 508 979 286 483 776 71 580 438 6...
output:
502
result:
ok 1 number(s): "502"
Test #3:
score: -100
Time Limit Exceeded
input:
900 1000 232 890 107 425 399 19 5 74 753 105 333 163 779 42 582 359 647 524 767 409 48 239 780 443 484 489 546 97 634 562 627 866 714 500 357 590 60 728 591 407 686 210 547 32 370 76 772 500 407 584 772 73 699 69 332 847 516 829 754 727 562 756 678 819 303 128 781 667 263 535 672 767 89 762 216 878 ...