# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
22764 | dried chocochip on Daegu asphalt (#40) | Logistical Metropolis (KRIII5_LM) | C++98 | 103 ms | 4852 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// Created by Acka on 2017. 4. 30..
//
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
struct Edge{
int u, v, c;
Edge(){}
Edge(int u, int v, int c):u(u), v(v), c(c){}
bool operator <(const Edge &A)const{
return c < A.c;
}
};
int par[1001];
Edge edge[300000];
vector<Edge> adj[1001];
int find(int x){
return x == par[x] ? x : par[x] = find(par[x]);
}
void link(int x, int y){
par[find(y)] = find(x);
}
int main()
{
int N, M; scanf("%d %d", &N, &M);
for(int i = 0, x, y, c; i < M; i++){
scanf("%d %d %d", &x, &y, &c);
edge[i] = Edge(x, y, c);
adj[x].push_back(Edge(0, y, c));
adj[y].push_back(Edge(0, x, c));
}
sort(edge, edge + M);
for(int o = 1; o <= N; o++){
for(int i = 1; i <= N; i++)
par[i] = i;
int sum = 0;
for(int i = 0; i < adj[o].size(); i++){
link(o, adj[o][i].v);
sum += adj[o][i].c;
}
for(int i = 0; i < M; i++){
int pu = find(edge[i].u), pv = find(edge[i].v);
if(pu == pv) continue;
link(pu, pv);
sum += edge[i].c;
}
printf("%d\n", sum);
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |