#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll,ll> Pll;
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define rep(i, n) for(int i=0;i<n;i++)
#define repp(i, n) for(int i=1;i<=n;i++)
#define all(x) x.begin(), x.end()
#define ABS(x) (((x) > 0 ) ? (x) : (-(x)))
#define MAX2(x, y) (((x) > (y)) ? (x) : (y))
#define MIN2(x, y) (((x) < (y)) ? (x) : (y))
#define MAX3(x, y, z) ( (x) > (y) ? ( (x) > (z) ? (x) : (z) ) : ( (y) > (z) ? (y) : (z) ) )
#define MIN3(x, y, z) ( (x) < (y) ? ( (x) < (z) ? (x) : (z) ) : ( (y) < (z) ? (y) : (z) ) )
#define MID3(val1,val2,val3) MAX2(MIN2(MAX2(val1,val2),val3),MIN2(val1,val2))
#define geti1(X) scanf("%d",&X)
#define geti2(X,Y) scanf("%d%d",&X,&Y)
#define geti3(X,Y,Z) scanf("%d%d%d",&X,&Y,&Z)
#define geti4(X,Y,Z,W) scanf("%d%d%d%d",&X,&Y,&Z,&W)
#define GET_MACRO(_1,_2,_3,_4,NAME,...) NAME
#define geti(...) GET_MACRO(__VA_ARGS__, geti4, geti3, geti2, geti1) (__VA_ARGS__)
#define INF 987654321
#define IINF 987654321987654321
#define insert push_back
int N,M,T,K,H;
vector<Pi> E[1050]; vector<pair<int,Pi>> Elist;
int pa[1050];
int find(int x){
if( pa[x] == x )return x;
return pa[x] = find(pa[x]);
}
void uni(int a, int b){
a = find(a); b = find(b);
pa[a] = b;
}
void solve(int n){
rep(i,1050) pa[i] = i;
int ans = 0;
for(auto e : E[n]){
uni(e.Fi, n);
ans += e.Se;
}
sort(all(Elist));
for(auto e : Elist){
int x = e.Se.Fi; int y = e.Se.Se;
if( find(x) != find(y) ){
ans += e.Fi;
uni(x,y);
}
}
printf("%d\n",ans);
}
int main(){
geti(N,M);
repp(i,M){
int a,b,c; geti(a,b,c);
E[a].push_back({b,c});
E[b].push_back({a,c});
Elist.push_back({c,{a,b}});
}
repp(i,N){
solve(i);
}
}
Compilation message
LM.cpp: In function 'int main()':
LM.cpp:81:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
geti(N,M);
^
LM.cpp:83:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int a,b,c; geti(a,b,c);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
126 ms |
2200 KB |
Output is correct |
2 |
Correct |
126 ms |
2200 KB |
Output is correct |
3 |
Correct |
123 ms |
2204 KB |
Output is correct |
4 |
Correct |
133 ms |
2200 KB |
Output is correct |
5 |
Correct |
126 ms |
2200 KB |
Output is correct |
6 |
Correct |
129 ms |
2200 KB |
Output is correct |
7 |
Correct |
123 ms |
2200 KB |
Output is correct |
8 |
Correct |
133 ms |
2200 KB |
Output is correct |
9 |
Correct |
129 ms |
2200 KB |
Output is correct |
10 |
Correct |
126 ms |
2200 KB |
Output is correct |
11 |
Correct |
159 ms |
2200 KB |
Output is correct |
12 |
Correct |
176 ms |
2200 KB |
Output is correct |
13 |
Correct |
183 ms |
2200 KB |
Output is correct |
14 |
Correct |
183 ms |
2200 KB |
Output is correct |
15 |
Correct |
166 ms |
2200 KB |
Output is correct |
16 |
Correct |
93 ms |
2200 KB |
Output is correct |
17 |
Correct |
93 ms |
2200 KB |
Output is correct |
18 |
Correct |
103 ms |
2200 KB |
Output is correct |
19 |
Correct |
93 ms |
2200 KB |
Output is correct |
20 |
Correct |
93 ms |
2200 KB |
Output is correct |
21 |
Correct |
93 ms |
2200 KB |
Output is correct |
22 |
Correct |
89 ms |
2200 KB |
Output is correct |
23 |
Correct |
89 ms |
2200 KB |
Output is correct |
24 |
Correct |
93 ms |
2200 KB |
Output is correct |
25 |
Correct |
0 ms |
2052 KB |
Output is correct |
26 |
Correct |
0 ms |
2052 KB |
Output is correct |
27 |
Correct |
0 ms |
2052 KB |
Output is correct |
28 |
Correct |
26 ms |
2052 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
0 ms |
2052 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |