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;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second
int n, m;
vector<pp> edge[100010];
vector<pair<int,pp>> E;
int par[1010];
int R(int x){ return (par[x]==x)?x:(par[x]=R(par[x])); }
bool unite(int a, int b){
a=R(a); b=R(b);
if(a==b) return 0;
par[a]=b; return 1;
}
int main()
{
read(n, m);
n=min(n, 1000);
m=min(m, 3000);
for(;m--;){
int x, y, c;
read(x, y, c);
E.emplace_back(c, pp{x, y});
edge[x].emplace_back(y, c);
edge[y].emplace_back(x, c);
}
sort(all(E));
for(int i=1; i<=n; ++i){
for(int j=1; j<=n; ++j) par[j]=j;
int ans=0;
for(auto tmp:edge[i]){
int j,k; tie(j,k)=tmp;
unite(i, j);
ans += k;
}
for(auto tmp:E){
int c=tmp.x, x=tmp.y.x, y=tmp.y.y;
if(unite(x, y)) ans+=c;
}
printf("%d\n", ans);
}
return 0;
}
Compilation message (stderr)
LM.cpp: In function 'void read(int&)':
LM.cpp:6:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
void read(int& x){ scanf("%d",&x); }
^
LM.cpp: In function 'void read(ll&)':
LM.cpp:7:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
void read(ll& x){ scanf("%lld",&x); }
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |