This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
struct point {
int u,v,w;
};
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
vector<point>adj(n);
for (int i =0;i<n;++i){
cin>>adj[i].u>>adj[i].v>>adj[i].w;
}
sort(adj.begin(),adj.end(),[&](point a,point b){
return a.w>b.w;
});
int64_t score=0;
vector<bool>visited(n,false);
vector<bool>visited2(n,false);
for (int i =0;i<n;++i){
if (visited[i])continue;
for (int j =i+1;j<n;++j){
if (!visited[j]){
if ((adj[i].u==adj[j].u&&!visited2[adj[i].u])){
visited[j]=true;
score+=adj[i].w+adj[j].w;
visited2[adj[i].u]=true;
break;
}
else if ((adj[i].u==adj[j].v&&!visited2[adj[j].v])){
visited[j]=true;
score+=adj[i].w+adj[j].w;
visited2[adj[i].u]=true;
break;
}
else if ((adj[i].v==adj[j].u&&!visited2[adj[j].u])){
visited[j]=true;
score+=adj[i].w+adj[j].w;
visited2[adj[i].v]=true;
break;
}
else if ((adj[i].v==adj[j].v&&!visited[adj[j].v])){
visited[j]=true;
score+=adj[i].w+adj[j].w;
visited2[adj[i].v]=true;
}}
}
}
cout<<score<<endl;
return 0;}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |