QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202203#6402. MEXimum Spanning Treeucup-team870WA 258ms3700kbC++171.3kb2023-10-05 20:42:142023-10-05 20:42:14

Judging History

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

  • [2023-10-05 20:42:14]
  • 评测
  • 测评结果:WA
  • 用时:258ms
  • 内存:3700kb
  • [2023-10-05 20:42:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define per(i,j,k) for(int i=j;i>=k;--i)
#define P pair<int,int>
#define ll long long
#define vi vector<int>
#define db double
const int N=1005;
int fa[N];
vector<P>tu[N];
int fd(int x){
    if(x==fa[x])return x;
    return fa[x]=fd(fa[x]);
}
signed main(){
    IOS
    int n,m;cin>>n>>m;
    rep(i,1,m){
        int u,v,w; cin>>u>>v>>w;
        tu[w].push_back({u,v});
    }
    auto ck=[&](int res){
        per(_,1e7/m,1){
            rep(i,1,n)fa[i]=i;
            rep(i,0,res){
                random_shuffle(tu[i].begin(),tu[i].end());
                int fl=1;
                for(auto [u,v]:tu[i]){
                    u=fd(u),v=fd(v);
                    if(u!=v){
                        fa[u]=v; fl=0; break;
                    }
                }
                if(fl)break;
                if(i==res)return true;
            }
        }
        return false;
    };
    int L=0,R=n;
    rep(i,0,n+1){
        if(!ck(i)){
            cout<<i; return 0;
        }
    }
    // while(L<=R){
    //     int mid=L+R>>1;
    //     if(ck(mid))L=mid+1;
    //     else R=mid-1;
    // }
    // cout<<L;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 63ms
memory: 3692kb

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: 97ms
memory: 3700kb

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
Wrong Answer
time: 258ms
memory: 3672kb

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 ...

output:

767

result:

wrong answer 1st numbers differ - expected: '801', found: '767'