結果

問題 No.1817 Reversed Edges
ユーザー tailstails
提出日時 2022-03-09 19:18:23
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 11 ms / 2,000 ms
コード長 1,081 bytes
コンパイル時間 1,278 ms
コンパイル使用メモリ 31,436 KB
実行使用メモリ 9,108 KB
最終ジャッジ日時 2023-10-11 20:26:33
合計ジャッジ時間 3,934 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,372 KB
testcase_01 AC 1 ms
4,368 KB
testcase_02 AC 1 ms
4,372 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 0 ms
4,372 KB
testcase_06 AC 1 ms
4,372 KB
testcase_07 AC 10 ms
6,372 KB
testcase_08 AC 4 ms
4,912 KB
testcase_09 AC 9 ms
6,100 KB
testcase_10 AC 5 ms
5,020 KB
testcase_11 AC 6 ms
5,452 KB
testcase_12 AC 11 ms
6,628 KB
testcase_13 AC 11 ms
6,620 KB
testcase_14 AC 11 ms
6,760 KB
testcase_15 AC 10 ms
6,780 KB
testcase_16 AC 11 ms
6,724 KB
testcase_17 AC 11 ms
6,684 KB
testcase_18 AC 11 ms
6,708 KB
testcase_19 AC 11 ms
6,732 KB
testcase_20 AC 10 ms
6,820 KB
testcase_21 AC 11 ms
6,620 KB
testcase_22 AC 4 ms
6,352 KB
testcase_23 AC 4 ms
6,360 KB
testcase_24 AC 8 ms
9,108 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘f2’ 内:
main.c:67:9: 警告: 関数 ‘write’ の暗黙的な宣言です [-Wimplicit-function-declaration]
   67 |         write(1,wbuf,wp-wbuf);
      |         ^~~~~
main.c: 関数 ‘main’ 内:
main.c:74:9: 警告: implicit declaration of function ‘_exit’; did you mean ‘_Exit’? [-Wimplicit-function-declaration]
   74 |         _exit(0);
      |         ^~~~~
      |         _Exit

ソースコード

diff #

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

#define rd(v) long v=0;{long _c;while(_c=*rp++-48,_c>=0)v=v*10+_c;}
#define wt(v) {ulong _z=v,_n=0,_d=0;while(++_n,_d=_d<<8|0x30|_z%10,_z/=10);*(ulong*)wp=_d;wp+=_n;}
#define rep(v,e) for(long v=0;v<e;++v)

typedef unsigned long ulong;
char*mmap();
char wbuf[1<<25];

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

int r[MAXN+1];
long o;

void f(int i,int p,int a){
	r[i]=a;
	for(int k=0;k<en[i];++k){
		int j=eb[ei[i]+k];
		if(j!=p){
			o+=!(i<j);
			f(j,i,a+(i<j?1:-1));
		}
	}
}

long f1(){
	char*rp=mmap(0l,1l<<25,1,2,0,0ll);
	rd(n);
	{
		int ne=n-1<<1;
		for(int j=0;j<ne;++j){
			rd(t);
			uv[j]=t;
			++ei[uv[j]];
		}
	}
	{
		int s=0;
		for(int i=0;++i<=n;){
			int t=s;
			s+=ei[i];
			ei[i]=t;
		}
	}
	{
		int ne=n-1<<1;
		for(int j=0;j<ne;++j){
			int i=uv[j];
			eb[ei[i]+en[i]++]=uv[j^1];
		}
	}
	return n;
}

long f2(long n){
	char*wp=wbuf;
	rep(i,n){
		wt(o+r[i+1]);
		*wp++='\n';
	}
	write(1,wbuf,wp-wbuf);
}

int main(){
	long n=f1();
	f(1,1,0);
	f2(n);
	_exit(0);
}
0