Skip to content

Commit 0588d3c

Browse files
committed
[Gold IV] Title: Networking, Time: 4 ms, Memory: 2024 KB -BaekjoonHub
1 parent 68921c1 commit 0588d3c

2 files changed

Lines changed: 35 additions & 20 deletions

File tree

C++17/백준/Gold/3803. Networking/Networking.cc

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,44 @@
1+
#include <algorithm>
12
#include <iostream>
23
#include <vector>
3-
#include <algorithm>
44
using namespace std;
55

6-
const int N = 51;
7-
int nodes[ N ];
8-
int n, m;
6+
const uint8_t N = 51;
7+
uint8_t nodes[ N ];
8+
int n;
9+
int m;
10+
911
struct Edge
1012
{
11-
int f, t, w;
12-
bool operator<(const Edge& other) const
13+
uint8_t f, t, w;
14+
bool operator<( const Edge& other ) const
1315
{
1416
return w < other.w;
1517
}
1618
};
17-
vector<Edge> edges;
19+
vector< Edge > edges;
1820

19-
int Find( int a )
21+
int Find( uint8_t a )
2022
{
21-
if ( nodes[ a ] == a ) return a;
23+
if ( nodes[ a ] == a )
24+
return a;
2225
return nodes[ a ] = Find( nodes[ a ] );
2326
}
2427

25-
bool Union( int a, int b )
28+
bool Union( uint8_t a, uint8_t b )
2629
{
27-
int A = Find( a );
28-
int B = Find( b );
29-
if ( A == B ) return false;
30+
uint8_t A = Find( a );
31+
uint8_t B = Find( b );
32+
33+
if ( A == B )
34+
return false;
35+
3036
nodes[ B ] = A;
3137
return true;
3238
}
3339

34-
int main() {
40+
int main()
41+
{
3542
ios::sync_with_stdio( 0 );
3643
cin.tie( 0 );
3744
cout.tie( 0 );
@@ -41,20 +48,28 @@ int main() {
4148
{
4249
cin >> m;
4350
edges.clear();
44-
for ( int i = 1; i <= n; ++i )
51+
for ( uint8_t i = 1; i <= n; ++i )
4552
nodes[ i ] = i;
4653

4754
while ( m-- )
4855
{
49-
int f, t, w; cin >> f >> t >> w;
50-
edges.push_back( { f, t, w } );
56+
int f, t, w;
57+
cin >> f >> t >> w;
58+
edges.push_back( {
59+
static_cast< uint8_t >( f ),
60+
static_cast< uint8_t >( t ),
61+
static_cast< uint8_t >( w )
62+
} );
5163
}
5264

5365
sort( edges.begin(), edges.end() );
54-
int sum = 0, cnt = 0;
66+
uint16_t sum = 0;
67+
uint8_t cnt = 0;
68+
5569
for ( const Edge& edge : edges )
5670
{
5771
const auto& [f, t, w] = edge;
72+
5873
if ( Union( f, t ) )
5974
{
6075
sum += w;

C++17/백준/Gold/3803. Networking/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
### 성능 요약
66

7-
메모리: 2164 KB, 시간: 4 ms
7+
메모리: 2024 KB, 시간: 4 ms
88

99
### 분류
1010

1111
그래프 이론, 최소 스패닝 트리
1212

1313
### 제출 일자
1414

15-
2026년 2월 27일 22:16:34
15+
2026년 2월 27일 22:55:35
1616

1717
### 문제 설명
1818

0 commit comments

Comments
 (0)