Submission #423465

#TimeUsernameProblemLanguageResultExecution timeMemory
423465ApiramBeads and wires (APIO14_beads)C++14
0 / 100
1 ms204 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...