結果

問題 No.1769 Don't Stop the Game
ユーザー kotatsugamekotatsugame
提出日時 2021-11-26 23:39:04
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 812 ms / 3,000 ms
コード長 954 bytes
コンパイル時間 928 ms
コンパイル使用メモリ 84,644 KB
実行使用メモリ 65,232 KB
最終ジャッジ日時 2023-09-12 05:38:15
合計ジャッジ時間 14,631 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
10,592 KB
testcase_01 AC 4 ms
10,600 KB
testcase_02 AC 4 ms
10,548 KB
testcase_03 AC 5 ms
10,576 KB
testcase_04 AC 4 ms
10,576 KB
testcase_05 AC 5 ms
10,648 KB
testcase_06 AC 5 ms
10,688 KB
testcase_07 AC 6 ms
10,812 KB
testcase_08 AC 366 ms
18,096 KB
testcase_09 AC 328 ms
18,380 KB
testcase_10 AC 549 ms
23,320 KB
testcase_11 AC 276 ms
16,164 KB
testcase_12 AC 320 ms
19,480 KB
testcase_13 AC 328 ms
19,636 KB
testcase_14 AC 347 ms
19,572 KB
testcase_15 AC 381 ms
19,604 KB
testcase_16 AC 481 ms
20,140 KB
testcase_17 AC 642 ms
23,000 KB
testcase_18 AC 770 ms
29,692 KB
testcase_19 AC 786 ms
29,632 KB
testcase_20 AC 810 ms
32,524 KB
testcase_21 AC 803 ms
29,964 KB
testcase_22 AC 812 ms
31,312 KB
testcase_23 AC 309 ms
19,584 KB
testcase_24 AC 320 ms
19,652 KB
testcase_25 AC 162 ms
19,760 KB
testcase_26 AC 482 ms
29,008 KB
testcase_27 AC 223 ms
55,904 KB
testcase_28 AC 658 ms
65,232 KB
testcase_29 AC 615 ms
48,096 KB
testcase_30 AC 640 ms
48,200 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:43:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   43 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
using namespace std;
int N;
vector<pair<int,int> >G[2<<17];
int ch[2<<17],Xr[2<<17];
int add[2<<17];
map<int,int>ret;
int dfs(int u,int p,int xr)
{
	Xr[u]=xr;
	ch[u]=1;
	map<int,int>now;
	for(pair<int,int>&e:G[u])
	{
		int v=e.first;
		if(v==p)continue;
		ch[u]+=dfs(v,u,xr^e.second);
		e.second=ret[Xr[u]];
		if(now.size()<ret.size())now.swap(ret);
		for(pair<int,int>p:ret)now[p.first]+=p.second;
	}
	ret.swap(now);
	add[u]=ch[u]-ret[Xr[u]];
	ret[Xr[u]]=ch[u];
	return ch[u];
}
long ans;
void dfs2(int u,int p)
{
	int tmp=ret[Xr[u]];
	ans-=tmp-add[u];
	for(pair<int,int>e:G[u])
	{
		int v=e.first;
		if(v==p)continue;
		ret[Xr[u]]=e.second+N-ch[v];
		dfs2(v,u);
	}
	ret[Xr[u]]=tmp;
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int a,b,c;cin>>a>>b>>c;
		a--,b--;
		G[a].push_back(make_pair(b,c));
		G[b].push_back(make_pair(a,c));
	}
	dfs(0,-1,0);
	ans=(long)N*(N-1);
	dfs2(0,-1);
	cout<<ans<<endl;
}
0