티스토리 뷰
문제
https://www.acmicpc.net/problem/10159
10159번: 저울
첫 줄에는 물건의 개수 N 이 주어지고, 둘째 줄에는 미리 측정된 물건 쌍의 개수 M이 주어진다. 단, 5 ≤ N ≤ 100 이고, 0 ≤ M ≤ 2,000이다. 다음 M개의 줄에 미리 측정된 비교 결과가 한 줄에 하나씩
www.acmicpc.net
문제해결
플로이드-워셜 알고리즘
결과
소스코드
#include<iostream>
#include<algorithm>
using namespace std;
const int LM = 105;
int map[LM][LM];
int ans[LM];
int n, m;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n;
cin >> m;
while (m--)
{
int a, b;
cin >> a >> b;
map[a][b] = 1;
}
for (int k = 1; k <= n; k++)
{
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
map[i][j] = max(map[i][j], (map[i][k]&map[k][j]));
}
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
if (i!=j && map[i][j] == 0 && map[j][i]==0)
{
ans[i]++;
}
}
}
for (int i = 1; i <= n; i++)
{
cout << ans[i] << "\n";
}
return 0;
}
728x90
반응형
'컴슈니 - 문제해결' 카테고리의 다른 글
[백준] 1238번: 파티 (0) | 2023.08.08 |
---|---|
[백준] 22865번: 가장 먼 곳 (0) | 2023.08.08 |
[백준] 1956번 : 운동 (0) | 2023.08.07 |
[백준] 11404번 : 플로이드 (0) | 2023.08.07 |
[백준] 2224번: 명제 증명 (0) | 2023.08.07 |
반응형
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- C++
- 동적계획법
- std::unique_lock
- std::async
- std::shared_ptr
- 다이나믹프로그래밍
- 유폰
- Thread
- Everyday
- conditional_variable
- unique_lock
- std::promise
- c++동기화
- step4
- Future
- semaphore
- 백준
- every day
- 영어글쓰기
- syncronization
- shared_ptr
- scoped_lock
- std::atomic
- the same
- std::counting_semaphore
- atomic
- Async
- 영어작문
- 민병철유폰
- std::future
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 |
글 보관함