結果

問題 No.1103 Directed Length Sum
コンテスト
ユーザー tatt61880
提出日時 2021-04-05 16:11:45
言語 Kuin
(KuinC++ v.2021.9.17)
コンパイル:
kuinc -i _filename_ -o out.cpp -s /kuin/sys/ -e cpp -r -q
実行:
./a.out
結果
WA  
実行時間 -
コード長 1,247 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 5,619 ms
コンパイル使用メモリ 168,444 KB
実行使用メモリ 285,312 KB
最終ジャッジ日時 2026-04-05 17:30:55
合計ジャッジ時間 8,234 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other WA * 1 TLE * 1 -- * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
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:1647:11: note: in instantiation of function template specialization 'newArrays_<std::shared_ptr<Array_<std::shared_ptr<k_ap>>>, long>' requested here
 1647 | (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*)
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 long>' requested here
  688 |         return newArraysRec_<T>()(std::forward<A>(a)...);
      |                ^
out.cpp:1841:19: note: in instantiation of function template specialization 'newArrays_<std::shared_ptr<Array_<std::shared_ptr<k_ap>>>, long long>' requested here
 1841 | ((k_fn)->k_bo) = (newArrays_<type_(Array_<type_(k_ap)>)>((0LL)));
      |                   ^
out.cpp:676:14: note: explicitly cast the pointer to silence this warning
  676 |          

ソースコード

diff #
raw source code

func main()
	class Node()
		+var parent: Node
		+var children: []Node
		+var depth: int
		+var num: int
		*func ctor()
			do me.parent :: null
			do me.children :: #[0]Node
		end func
		+func calcDepth()
			if(me.parent =& null)
				do me.depth :: 1
			else
				do me.depth :: me.parent.depth + 1
			end if
			for i(0, ^me.children - 1)
				do me.children[i].calcDepth()
			end for
		end func
		+func calcNum()
			if(^me.children = 0)
				do me.num :: 0
				ret
			end if
			for i(0, ^me.children - 1)
				do me.children[i].calcNum()
				do me.num :+ me.children[i].num + 1
			end for
		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 as: []int :: #[n - 1]int
	var bs: []int :: #[n - 1]int
	for i(0, n - 2)
		var a: int :: cui@inputInt() - 1
		var b: int :: cui@inputInt() - 1
		do as[i] :: a
		do bs[i] :: b
		do nodes[a].children :~ [nodes[b]]
		do nodes[b].parent :: nodes[a]
	end for
	var root: Node
	for i(0, n - 1)
		if(nodes[i].parent =& null)
			do root :: nodes[i]
		end if
	end for
	
	do root.calcDepth()
	do root.calcNum()
	
	var ans: int :: 0
	for i(0, n - 1)
		do ans :+ nodes[i].depth * nodes[i].num
	end for
	do cui@print("\{ans}\n")
end func
0