結果

問題 No.1147 土偶Ⅱ
ユーザー forest3forest3
提出日時 2020-08-07 13:44:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 500 ms
コード長 725 bytes
コンパイル時間 1,427 ms
コンパイル使用メモリ 169,400 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-19 18:06:15
合計ジャッジ時間 2,105 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 3 ms
6,940 KB
testcase_08 AC 1 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 3 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 3 ms
6,940 KB
testcase_15 AC 2 ms
6,940 KB
testcase_16 AC 2 ms
6,944 KB
testcase_17 AC 1 ms
6,944 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 2 ms
6,940 KB
testcase_21 AC 1 ms
6,940 KB
testcase_22 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	const int INF = INT32_MAX / 2;
	vector<vector<int>> mat( n, vector<int>( n, INF ) );
	for( int i = 0; i < n; i++ ) mat[i][i] = 0;
	for( int i = 0; i < m; i++ ) {
		int a, b;
		cin >> a >> b;
		a--;
		b--;
		mat[a][b] = 1;
		mat[b][a] = 1;
	}

	for( int k = 0; k < n; k++ ) {
		for( int i = 0; i < n; i++ ) {
			for( int j = 0; j < n; j++ ) {
				mat[i][j] = min( mat[i][j], mat[i][k] + mat[k][j] );
			}
		}
	}
	int ans = 0;
	for( int i = 0; i < n; i++ ) {
		for( int j = i + 1; j < n; j++ ) {
			for( int k = j + 1; k < n; k++ ) {
				if( mat[i][j] != 2 && mat[j][k] != 2 && mat[k][i] != 2 ) ans++;
			}
		}
	}

	cout << ans << endl;
}
0