結果

問題 No.277 根掘り葉掘り
ユーザー syoken_desukasyoken_desuka
提出日時 2015-09-04 23:42:46
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,717 bytes
コンパイル時間 2,420 ms
コンパイル使用メモリ 151,348 KB
実行使用メモリ 5,644 KB
最終ジャッジ日時 2023-09-26 07:20:18
合計ジャッジ時間 5,094 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 WA -
testcase_03 AC 3 ms
4,560 KB
testcase_04 AC 2 ms
4,556 KB
testcase_05 WA -
testcase_06 AC 2 ms
4,416 KB
testcase_07 WA -
testcase_08 AC 2 ms
4,380 KB
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:28:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG1{}
               ^
main.cpp:28: warning: "DEBUG1" redefined
 #define DEBUG1{}
 
main.cpp:23: note: this is the location of the previous definition
 #define DEBUG1(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
 
main.cpp:29:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG2{}
               ^
main.cpp:29: warning: "DEBUG2" redefined
 #define DEBUG2{}
 
main.cpp:24: note: this is the location of the previous definition
 #define DEBUG2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG1(var1); }
 
main.cpp:30:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG3{}
               ^
main.cpp:30: warning: "DEBUG3" redefined
 #define DEBUG3{}
 
main.cpp:25: note: this is the location of the previous definition
 #define DEBUG3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG2(var1, var2); }
 
main.cpp:31:15: warning: ISO C++11 requires whitespace after the macro name
 #define DEBUG4{}
               ^
main.cpp:31: warning: "DEBUG4" redefined
 #define DEBUG4{}
 
main.cpp:26: note: this is the location of the previous definition
 #define DEBUG4(var0, var1, var2, var3) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG3(var1, var2, var3); }
 

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
//諸機能
#pragma region MACRO
#define ANSWER(x) cerr << "answer: "; cout << (x) << endl
#define DOUBLE_ANSWER(x) cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define ALL(a) begin((a)),end((a))
#define FILL(a,n) for(auto &hoge : (a)) hoge = (n)
#define mp make_pair
#define EXIST(container, n) ((container).find((n)) != (container).end())
#define STOI(s,i,l) stoi(SUBSTR(s,i,l))
#define SUBSTR(s,i,l) string((s), (i), (l))
#define NPI_TO_RAD(x) (180.0*x/PI)
#define RAD_TO_NPI(x) (PI/180.0*x)
#pragma endregion

//デバッグなどの支援
#pragma region CODING_SUPPORT
#define DEBUG1(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define DEBUG2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG1(var1); }
#define DEBUG3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG2(var1, var2); }
#define DEBUG4(var0, var1, var2, var3) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; DEBUG3(var1, var2, var3); }
#ifndef _DEBUG //デバッグでないなら、計算時間短縮のためにエラー出力を無効化
#define DEBUG1{}
#define DEBUG2{}
#define DEBUG3{}
#define DEBUG4{}
#endif

//typedef(書き換える、書き足す可能性ある)
#pragma region TYPE_DEF
typedef long long ll; 
typedef pair<int,int> pii;
typedef pair<string,string> pss;
typedef pair<int,string>pis;
typedef pair<string,int>psi;
typedef vector<string> vs;
typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9 + 7)
#pragma endregion



int l[100000];
vector<int> link[10000];

void l_search(int n) 
{

	if (link[n].size() == 0)
	{
		DEBUG1(n);
		l[n] = 0;
		return;
	}
	DEBUG2(n,link[n].size());
	rep(i, link[n].size())
	{

		l_search(link[n][i]);
		l[n] = min(l[n], l[link[n][i]] +1);
	}
	DEBUG2(n,l[n]);
}

int main()
{
	int n;
	cin >> n;

	int r[100000];

	FILL(r,-1);
	FILL(l, 10000000);
	queue<pii> q;
	rep(i, n-1)
	{
		int x, y;
		cin >> x >> y;
		link[x - 1].push_back(y-1);
		q.push(mp(x-1, y-1));
	}
	r[0] = 0;
	while (!q.empty())
	{
		pii t = q.front();
		DEBUG2(t.first, t.second);
		q.pop();
		if (r[t.first] != -1)
		{
			r[t.second] = r[t.first] + 1;
			DEBUG2(t.second, r[t.second]);
		}
		else if (t.second != -1)
		{
			r[t.first] = r[t.second] + 1;
			DEBUG2(t.first,r[t.first]);
		}
		else
		{
			q.push(t);
		}
	}
	l_search(0);
	rep(i, n)
	{
		ANSWER(min(r[i], l[i]));
	}
	return 0;

}
0