Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25c3bee

Browse files
committed
Lv2_전력망을둘로나누기
1 parent ba25dce commit 25c3bee

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <string>
2+
#include <vector>
3+
#include <iostream>
4+
#include <queue>
5+
using namespace std;
6+
7+
bool arr[101][101];
8+
9+
int solution(int n, vector<vector<int>> wires) {
10+
int answer = n;
11+
int count = 0;
12+
13+
for (auto a : wires) {
14+
arr[a[0]][a[1]] = true;
15+
arr[a[1]][a[0]] = true;
16+
}
17+
18+
for (auto a : wires) {
19+
arr[a[0]][a[1]] = false;
20+
arr[a[1]][a[0]] = false;
21+
22+
count = 1;
23+
24+
queue<int> q;
25+
vector<bool> check(101, false);
26+
27+
q.push(1);
28+
check[1] = true;
29+
while (!q.empty()) {
30+
int now = q.front();
31+
q.pop();
32+
33+
for (int i = 1; i <= n; ++i) {
34+
if (!check[i] && arr[now][i]) {
35+
++count;
36+
q.push(i);
37+
check[i] = true;
38+
}
39+
}
40+
}
41+
42+
if (abs(n-count-count) < answer)
43+
answer = abs(n - count - count);
44+
45+
if (answer == 0)
46+
break;
47+
48+
arr[a[0]][a[1]] = true;
49+
arr[a[1]][a[0]] = true;
50+
}
51+
52+
return answer;
53+
}
54+
55+
int main() {
56+
vector<vector<int>> wires1 = { {1, 3}, {2, 3}, {3, 4}, {4, 5}, {4, 6}, {4, 7}, {7, 8}, {7, 9} };
57+
vector<vector<int>> wires2 = {{1, 2}, {2, 3}, {3, 4}};
58+
vector<vector<int>> wires3 = {{1, 2}, {2, 7}, {3, 7}, {3, 4}, {4, 5}, {6, 7}};
59+
cout << solution(4, wires2);
60+
return 0;
61+
}

‎Programmers/Programmers.vcxproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,9 @@
284284
<ClCompile Include="Lv2\Lv2_위장.cpp">
285285
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
286286
</ClCompile>
287+
<ClCompile Include="Lv2\Lv2_전력망을둘로나누기.cpp">
288+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
289+
</ClCompile>
287290
<ClCompile Include="Lv2\Lv2_전화번호목록.cpp">
288291
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
289292
</ClCompile>

‎Programmers/Programmers.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,9 @@
582582
<ClCompile Include="Lv2\Lv2_교점에별만들기.cpp">
583583
<Filter>소스 파일\Lv2</Filter>
584584
</ClCompile>
585+
<ClCompile Include="Lv2\Lv2_전력망을둘로나누기.cpp">
586+
<Filter>소스 파일\Lv2</Filter>
587+
</ClCompile>
585588
</ItemGroup>
586589
<ItemGroup>
587590
<None Include="packages.config" />

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /