QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#757594#7883. Takeout Deliveringsurenjamts#WA 126ms45932kbC++201.4kb2024-11-17 11:00:362024-11-17 11:00:36

Judging History

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

  • [2024-11-17 11:00:36]
  • 评测
  • 测评结果:WA
  • 用时:126ms
  • 内存:45932kb
  • [2024-11-17 11:00:36]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define S second
#define int long long
int n,m;
int sz[300005];
int par[300005];
vector<tuple<int,int,int>> edges;
vector<pair<int,int>> adj[300005];
int fin(int x){
    if(par[x]==x) return x;
    else return fin(par[x]);
}
bool same(int x, int y){
    x=fin(x), y=fin(y);
    return x==y;
}
void unite(int x, int y){
    x=fin(x), y=fin(y);
    if(x==y){
        return;
    }
    if(sz[x]<sz[y]) swap(x,y);
    sz[x]+=sz[y];
    par[y]=x;
}
signed main(){
    ios::sync_with_stdio(0);
    cin.tie(NULL);
	cin>>n>>m;
	for(int i=0; i<m; i++){
        int u,v,w;
        cin>>u>>v>>w;
        edges.push_back({w,u,v});
        adj[u].push_back({w,v});
        adj[v].push_back({w,u});
	}
    for(int i=0; i<=n; i++){
        sz[i]=1;
        par[i]=i;
    }
    priority_queue<int> q;
    sort(edges.begin(),edges.end());
    for(auto [w,u,v] : edges){
        if(!same(u,v)){
            unite(u,v);
            q.push(w);
        }
      //  cout<<":L"<<endl;
        //cout<<w<<" "<<u<<" "<<v<<endl;
        int x=1, y=n;
        x=fin(x), y=fin(y);
        if(x==y){
             break;
        }
    }
    if(q.size()==1){
        cout<<q.top()<<endl;
    }
    else{
        int ans=q.top();
        q.pop();
        cout<<ans+q.top()<<endl;
    }
}

详细

Test #1:

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

input:

4 6
1 2 2
1 3 4
1 4 7
2 3 1
2 4 3
3 4 9

output:

5

result:

ok 1 number(s): "5"

Test #2:

score: 0
Accepted
time: 119ms
memory: 45544kb

input:

300000 299999
80516 80517 597830404
110190 110191 82173886
218008 218009 954561262
250110 250111 942489774
66540 66541 156425292
34947 34948 239499776
273789 273790 453201232
84428 84429 439418398
98599 98600 326095035
55636 55637 355015760
158611 158612 684292473
43331 43332 43265001
171621 171622 ...

output:

1999991697

result:

ok 1 number(s): "1999991697"

Test #3:

score: -100
Wrong Answer
time: 126ms
memory: 45932kb

input:

300000 299999
207226 231742 414945003
84591 210444 175968953
46327 51582 612565723
18773 141119 82562646
76139 286963 762958587
131867 224820 928900783
215240 216181 405340417
144725 290878 195350550
267216 268752 846015171
31413 255927 389339642
45219 147512 489502910
113391 215402 555706684
53359 ...

output:

1993274886

result:

wrong answer 1st numbers differ - expected: '1989898633', found: '1993274886'