結果

問題 No.1507 Road Blocked
ユーザー tailstails
提出日時 2021-05-16 22:32:15
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,305 bytes
コンパイル時間 1,185 ms
コンパイル使用メモリ 33,920 KB
実行使用メモリ 7,912 KB
最終ジャッジ日時 2024-04-15 13:16:00
合計ジャッジ時間 2,096 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,816 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 7 ms
7,912 KB
testcase_04 AC 9 ms
6,940 KB
testcase_05 AC 10 ms
6,940 KB
testcase_06 AC 10 ms
6,944 KB
testcase_07 AC 10 ms
6,944 KB
testcase_08 AC 10 ms
6,940 KB
testcase_09 AC 9 ms
6,944 KB
testcase_10 AC 9 ms
6,944 KB
testcase_11 AC 10 ms
6,944 KB
testcase_12 AC 10 ms
6,944 KB
testcase_13 AC 10 ms
6,944 KB
testcase_14 AC 10 ms
6,940 KB
testcase_15 AC 10 ms
6,940 KB
testcase_16 AC 10 ms
6,940 KB
testcase_17 AC 10 ms
6,940 KB
testcase_18 AC 9 ms
6,940 KB
testcase_19 AC 9 ms
6,940 KB
testcase_20 AC 10 ms
6,944 KB
testcase_21 AC 9 ms
6,940 KB
testcase_22 AC 10 ms
6,940 KB
testcase_23 AC 10 ms
6,940 KB
testcase_24 AC 10 ms
6,940 KB
testcase_25 AC 9 ms
6,940 KB
testcase_26 AC 10 ms
6,944 KB
testcase_27 AC 10 ms
6,940 KB
testcase_28 AC 9 ms
6,944 KB
testcase_29 AC 10 ms
6,944 KB
testcase_30 AC 11 ms
6,940 KB
testcase_31 AC 10 ms
6,940 KB
testcase_32 AC 10 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:49:1: warning: return type defaults to 'int' [-Wimplicit-int]
   49 | main(){
      | ^~~~
main.c: In function 'main':
main.c:84:9: warning: implicit declaration of function 'write' [-Wimplicit-function-declaration]
   84 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c:85:9: warning: implicit declaration of function '_exit'; did you mean '_Exit'? [-Wimplicit-function-declaration]
   85 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")

char*mmap();
#define rd(v) int v=0;{int _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}

#define WTHI(v) {long _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(long*)wp=_d;wp+=_n;}
#define WTLO(v) {long _z=v,_n=8,_d=0;while(_d=_d<<8|0x30|_z%10,_z/=10,--_n);*(long*)wp=_d;wp+=8;}
#define wt(v) if(v>=100000000){WTHI(v/100000000);WTLO(v);}else{WTHI(v);}

#define MD 998244353

int inverse(int a){
	int b=MD;
	int u=1;
	int v=0;
	while(b){
		int q=a/b,t;
		t=b, b=a-q*b, a=t;
		t=v, v=u-q*v, u=t;
	}
	if(u<0){
		u+=MD;
	}
	return u;
}

long n;
long a;

#define MAXN 100000
int en[MAXN+1];
int ei[MAXN+1];
int eb[MAXN<<1];
int uv[MAXN<<1];

long f(int i,int p){
	long d=1;
	for(int k=0;k<en[i];++k){
		int j=eb[ei[i]+k];
		if(j!=p){
			d+=f(j,i);
		}
	}
	a+=d*(n-d);
	return d;
}

main(){
	char*rp=mmap(0l,1l<<28,1,2,0,0ll);

	{
		rd(t);
		n=t;
	}
	{
		int ne=n-1<<1;
		for(int j=0;j<ne;++j){
			rd(t);
			uv[j]=t;
			++en[uv[j]];
		}
	}
	{
		int s=0;
		for(int i=0;++i<=n;){
			ei[i]=s;
			s+=en[i];
			en[i]=0;
		}
	}
	{
		int ne=n-1<<1;
		for(int j=0;j<ne;++j){
			int i=uv[j];
			eb[ei[i]+en[i]++]=uv[j^1];
		}
	}
	f(1,1);
	long r=(MD+1-a%MD*inverse(n*(n-1)/2*(n-1)%MD)%MD)%MD;

	char wbuf[32],*wp=wbuf;
	wt(r);
	write(1,wbuf,wp-wbuf);
	_exit(0);
}
0