結果

問題 No.806 木を道に
ユーザー sggkshiosggkshio
提出日時 2019-10-01 00:26:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 942 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 100,044 KB
実行使用メモリ 814,360 KB
最終ジャッジ日時 2023-07-26 18:54:43
合計ジャッジ時間 5,765 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #



#define _USE_MATH_DEFINES
#include  <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include<math.h>
#include<iomanip>
#include<stdio.h>
#include <stdlib.h>
#include<stdio.h>
#include <queue>
#include<map>
#include <sstream>
#include<set>
#include<stack>

//#include<bits/stdc++.h>


using namespace std;	

vector<vector<bool>>f;

int main() {

	int n;
	cin >> n;
	
	f.resize(n,vector<bool>(n));
	//cout << f[0].size();
	vector<int>p(n);
	vector<vector<int>>x(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		p[a]++; p[b]++;
		x[a].push_back(b);
		x[b].push_back(a);
		f[a][b] = 1;
		f[b][a] = 1;
	}
	long long int ans = 0;
	for (int i = 0; i < n; i++) {
		sort(x[i].begin(), x[i].end());
		if (p[i] >= 2)ans += p[i] - 2;
		for (int j = 0; j < x[i].size(); j++) {
			f[i][x[i][j]] = 0;
			p[x[i][j]]--;
		}
	}
	cout << ans << endl;



	return 0;




}
0