-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
8-seongwon030 #37
8-seongwon030 #37
Conversation
arr[a-1][b-1] = 1 # ๋ ธ๋ ์ ์ฅ | ||
arr[b-1][a-1] = 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๊ฑด ์ธ์ ๋ฆฌ์คํธ๊ฐ ์๋๋ผ ์ธ์ ํ๋ ฌ์ธ๋...?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ๋ 1์ด ์น๊ตฌ์ผ๋๋ง queue์ ์ง์ด ๋ฃ๋ ๋ฐฉ์์ผ๋ก ์ฒ๋ฆฌํด์ฃผ์์ต๋๋ค!
void Solve()
{
cin >> n >> m;
n++;
relation.assign(n, vector<int>());
visited.assign(n, false);
int a, b;
for (int i = 0; i < m; i++)
{
cin >> a >> b;
relation[a].push_back(b);
relation[b].push_back(a);
}
invite.push(1);
visited[1] = true;
while (!invite.empty())
{
int cur = invite.front();
invite.pop();
for (auto num : relation[cur])
{
if (visited[num]) continue;
if (cur == 1) invite.push(num);
answer.push_back(num);
visited[num] = true;
}
}
cout << answer.size();
}
2์ด ์ผ๋๋ queue์ ๋ฃ๋ ๊ฒ์ด ์๋ ๋ต์ ๋ฐ๋ก ์ฒดํฌ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bfs ์ํํ๋ฉด์ ์ ๋ต cnt ์ฐ์ฐ๋ ๊ฐ์ด ํ ์ ์์ ๊ฒ ๊ฐ์์!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ธ์ ํ๋ ฌ์ ์ด์ฉํ bfs ํ์ด
์๋ณด์์ต๋๋ค! ์ฝ๋๊ฐ ์ ์ฒด์ ์ผ๋ก ์ฝ๊ธฐ์ข๊ฒ ๊น๋ํ๊ฑฐ ๊ฐ์ต๋๋ค
๐ ๋ฌธ์ ๋งํฌ
๊ฒฐํผ์
โ๏ธ ์์๋ ์๊ฐ
1์๊ฐ
โจ ์๋ ์ฝ๋
2์ฐจ์ ๋ฆฌ์คํธ
์ ์ ์ฅํ๋ค.ex) ๋ง์ฝ
1 3
์ด๋ฉด 0๋ถํฐ ์ธ๋ฑ์ค๊ฐ ์์ํ๋ฏ๋กarr[0][2]
์arr[2][0]
์ ๊ฐ์ 1๋ก ์ค์ ํ๋ค.0์ผ๋ก ์ค์
ํ๋ค.->
์ธ๋ฑ์ค 0
์ ์๊ทผ์ด ์์ ์ด๋ฏ๋ก๋ฌด์กฐ๊ฑด ๋ฐฉ๋ฌธ์ฒ๋ฆฌ
์ฐ๊ฒฐ๋ ๋ ธ๋๊ฐ ๋ฐฉ๋ฌธ์ด ์๋์๋ค๋ฉด
ํ์ ์ถ๊ฐํ๊ณ ๋ฐฉ๋ฌธ์ฒ๋ฆฌํ๋ค.์์ ๋ ธ๋ 0
์ผ๋ก ํธ์ถํ๋ค.๐ ์๋กญ๊ฒ ์๊ฒ๋ ๋ด์ฉ
๏ฟฝ์ธ์ ๋ฆฌ์คํธ๋ก ๊ฐ์ ์ ๊ตฌํํด๋ดค์ต๋๋น