QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#202197#6402. MEXimum Spanning Treeucup-team870#WA 7ms3636kbC++141.1kb2023-10-05 20:39:062023-10-05 20:39:08

Judging History

你现在查看的是最新测评结果

  • [2023-10-05 20:39:08]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:3636kb
  • [2023-10-05 20:39:06]
  • 提交

answer

#include <bits/stdc++.h>
#define For(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define pb push_back
using namespace std;
int fa[2005];
struct node{
    int x,y,w;
}a[2005];
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
int mi[2005],ma[2005],cnt;
int merge(int id){
    int x=a[id].x,y=a[id].y;
    if (find(x)!=find(y)){
        fa[fa[x]]=fa[y]; return 1;//--cnt;
    }
    return 0;
}
int main(){
    int n,m; cin>>n>>m;
    For(i,1,m) cin>>a[i].x>>a[i].y>>a[i].w;
    For(now,0,n){
        //mi
        cnt=n-1;
        For(j,1,n) fa[j]=j;
        For(i,1,m) if (a[i].w>now) cnt-=merge(i);
        mi[now]=max(now+1,cnt);
        //ma
        cnt=0;
        For(j,1,n) fa[j]=j;
        For(i,1,m) if (a[i].w<=now) cnt+=merge(i);
        ma[now]=cnt;
        //cout<<mi[now]<<' '<<ma[now]<<endl;
    }
if (!ma[0])  printf("0\n"),exit(0);
    For(now,1,n){
        if (ma[now]<now+1||ma[now]<=mi[now-1]) printf("%d\n",now),exit(0);
    }
    printf("%d\n",n+1);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3564kb

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: -100
Wrong Answer
time: 7ms
memory: 3636kb

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:

928

result:

wrong answer 1st numbers differ - expected: '502', found: '928'