結果

問題 No.1507 Road Blocked
ユーザー kotatsugamekotatsugame
提出日時 2021-05-14 22:13:26
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 82 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 682 ms
コンパイル使用メモリ 73,588 KB
実行使用メモリ 16,000 KB
最終ジャッジ日時 2024-04-10 00:32:11
合計ジャッジ時間 4,233 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,812 KB
testcase_01 AC 4 ms
6,944 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 70 ms
16,000 KB
testcase_04 AC 82 ms
9,784 KB
testcase_05 AC 77 ms
9,844 KB
testcase_06 AC 75 ms
9,808 KB
testcase_07 AC 79 ms
9,856 KB
testcase_08 AC 74 ms
9,856 KB
testcase_09 AC 75 ms
9,904 KB
testcase_10 AC 78 ms
9,728 KB
testcase_11 AC 77 ms
9,764 KB
testcase_12 AC 80 ms
9,728 KB
testcase_13 AC 80 ms
9,856 KB
testcase_14 AC 82 ms
9,672 KB
testcase_15 AC 79 ms
9,836 KB
testcase_16 AC 81 ms
9,984 KB
testcase_17 AC 79 ms
9,768 KB
testcase_18 AC 77 ms
9,864 KB
testcase_19 AC 76 ms
9,856 KB
testcase_20 AC 80 ms
9,852 KB
testcase_21 AC 79 ms
9,728 KB
testcase_22 AC 79 ms
9,856 KB
testcase_23 AC 78 ms
9,836 KB
testcase_24 AC 75 ms
9,728 KB
testcase_25 AC 79 ms
9,824 KB
testcase_26 AC 73 ms
9,800 KB
testcase_27 AC 75 ms
9,856 KB
testcase_28 AC 77 ms
9,728 KB
testcase_29 AC 80 ms
9,704 KB
testcase_30 AC 76 ms
9,872 KB
testcase_31 AC 81 ms
9,856 KB
testcase_32 AC 78 ms
9,856 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:20:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   20 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<atcoder/modint>
using namespace std;
using mint=atcoder::modint998244353;
int N;
vector<int>G[1<<17];
mint ans;
int dfs(int u,int p)
{
	int ch=1;
	for(int v:G[u])if(v!=p)
	{
		int c=dfs(v,u);
		ch+=c;
		ans-=(long)c*(N-c)*2;
	}
	return ch;
}
main()
{
	cin>>N;
	ans=(mint)N*(N-1)*(N-1);
	for(int i=1;i<N;i++)
	{
		int u,v;cin>>u>>v;
		u--,v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(0,-1);
	cout<<(ans/N/(N-1)/(N-1)).val()<<endl;
}
0