結果

問題 No.872 All Tree Path
コンテスト
ユーザー tatt61880
提出日時 2021-04-05 20:06:07
言語 Kuin
(KuinC++ v.2021.9.17)
コンパイル:
kuinc -i _filename_ -o out.cpp -s /kuin/sys/ -e cpp -r -q
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,278 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,049 ms
コンパイル使用メモリ 166,076 KB
実行使用メモリ 77,440 KB
最終ジャッジ日時 2026-04-05 17:33:32
合計ジャッジ時間 5,484 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 6 WA * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
out.cpp:676:14: warning: first argument in call to 'memset' is a pointer to non-trivially copyable type 'std::shared_ptr<k_ap>' [-Wnontrivial-memcall]
  676 |                         memset(r->B, 0, sizeof(T) * static_cast<std::size_t>(h + bufLen_<T>()));
      |                                   ^
out.cpp:688:9: note: in instantiation of function template specialization 'newArraysRec_<std::shared_ptr<Array_<std::shared_ptr<k_ap>>>>::operator()<long>' requested here
  688 |         return newArraysRec_<T>()(std::forward<A>(a)...);
      |                ^
out.cpp:1646:11: note: in instantiation of function template specialization 'newArrays_<std::shared_ptr<Array_<std::shared_ptr<k_ap>>>, long>' requested here
 1646 | (k_ao) = (newArrays_<type_(Array_<type_(k_ap)>)>((k_am)));
      |           ^
out.cpp:676:14: note: explicitly cast the pointer to silence this warning
  676 |                         memset(r->B, 0, sizeof(T) * static_cast<std::size_t>(h + bufLen_<T>()));
      |                                   ^
      |                                (void*)
1 warning generated.

ソースコード

diff #
raw source code

func main()
	const mod: int :: 1000000007
	class Node()
		+var parent: Node
		+var children: list<Node>
		+var num: int
		*func ctor()
			do me.children :: #list<Node>
		end func
		+func calcNum()
			do me.children.head()
			for i(0, ^me.children - 1)
				var child: Node :: me.children.get()
				if(child.parent =& null)
					do child.parent :: me
					do child.calcNum()
					do me.num :+ child.num
				end if
				do me.children.next()
			end for
			do me.num :+ 1
		end func
	end class
	
	var n: int :: cui@inputInt()
	var nodes: []Node :: #[n]Node
	for i(0, n - 1)
		do nodes[i] :: #Node
	end for
	var u: []int :: #[n - 1]int
	var v: []int :: #[n - 1]int
	var w: []int :: #[n - 1]int
	for i(0, n - 2)
		do u[i] :: cui@inputInt() - 1
		do v[i] :: cui@inputInt() - 1
		do w[i] :: cui@inputInt()
		do nodes[u[i]].children.add(nodes[v[i]])
		do nodes[v[i]].children.add(nodes[u[i]])
	end for
	
	do nodes[0].parent :: nodes[0]
	do nodes[0].calcNum()
	
	var ans: int :: 0
	for i(0, n - 2)
		var num1: int
		if(nodes[u[i]].parent =& nodes[v[i]])
			do num1 :: nodes[u[i]].num
		else
			do num1 :: nodes[v[i]].num
		end if
		var num2: int :: n - num1
		do ans :+ num1 * num2 % mod * w[i] % mod
		do ans :% mod
	end for
	do ans :* 2
	do ans :% mod
	do cui@print("\{ans}\n")
end func
0