티스토리 뷰

백준

백준 소스코드 [C++] 10159 저울

Hani_Levenshtein 2021. 3. 5. 11:23

www.acmicpc.net/problem/10159

 

10159번: 저울

첫 줄에는 물건의 개수 N 이 주어지고, 둘째 줄에는 미리 측정된 물건 쌍의 개수 M이 주어진다. 단, 5 ≤ N ≤ 100 이고, 0 ≤ M ≤ 2,000이다. 다음 M개의 줄에 미리 측정된 비교 결과가 한 줄에 하나씩

www.acmicpc.net

백준 소스코드 [C++] 10159 저울

#include <iostream>
#include <algorithm>
#include <queue>
#include <string.h>
#include <limits.h>
#include <vector>
#include <math.h>
#include <stack>
#include <bitset>
#include <string>
#include <set>
#include <sstream>
#define all(v) v.begin(), v.end()
#define pii pair<int,int>
#define make_unique(v) v.erase(unique(v.begin(), v.end()), v.end())
typedef long long ll;
using namespace std;

int n,m,arr[100][100];

void floyd() {
	for (int via = 0;via < n;via++)
		for (int here = 0;here < n;here++)
			for (int next = 0;next < n;next++)
				if (arr[here][via] == 1 && arr[via][next] == 1)
					arr[here][next] = 1;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n;
	cin >> m;
	for (int i = 0;i < m;i++) {
		int u, v;
		cin >> u >> v;
		arr[u - 1][v - 1] = 1;
	}

	floyd();
	for (int i = 0;i < n;i++) {
		int res = 0;
		for (int j = 0;j < n;j++)
			if (arr[i][j] == 0 && arr[j][i] == 0 && i != j) res++;
		cout << res<<'\n';
	}
	
	return 0;
}
댓글