結果

問題 No.1582 Vertexes vs Edges
ユーザー 👑 ygussanyygussany
提出日時 2021-07-02 22:24:16
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,162 bytes
コンパイル時間 588 ms
コンパイル使用メモリ 28,948 KB
実行使用メモリ 7,384 KB
最終ジャッジ日時 2023-09-11 22:34:38
合計ジャッジ時間 3,209 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,816 KB
testcase_01 AC 1 ms
4,392 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 3 ms
5,544 KB
testcase_05 AC 20 ms
6,948 KB
testcase_06 AC 2 ms
4,820 KB
testcase_07 AC 4 ms
4,784 KB
testcase_08 AC 11 ms
5,536 KB
testcase_09 AC 18 ms
6,832 KB
testcase_10 AC 13 ms
6,316 KB
testcase_11 AC 3 ms
5,068 KB
testcase_12 AC 9 ms
4,956 KB
testcase_13 AC 15 ms
5,868 KB
testcase_14 AC 15 ms
5,756 KB
testcase_15 AC 20 ms
6,652 KB
testcase_16 AC 11 ms
5,972 KB
testcase_17 AC 14 ms
5,688 KB
testcase_18 AC 24 ms
7,048 KB
testcase_19 AC 15 ms
6,160 KB
testcase_20 AC 14 ms
6,684 KB
testcase_21 AC 11 ms
5,420 KB
testcase_22 AC 21 ms
6,876 KB
testcase_23 AC 10 ms
5,512 KB
testcase_24 AC 5 ms
4,852 KB
testcase_25 AC 12 ms
5,532 KB
testcase_26 AC 10 ms
5,556 KB
testcase_27 AC 21 ms
6,452 KB
testcase_28 AC 7 ms
5,260 KB
testcase_29 AC 18 ms
6,276 KB
testcase_30 AC 11 ms
5,396 KB
testcase_31 AC 19 ms
6,108 KB
testcase_32 AC 8 ms
6,380 KB
testcase_33 AC 28 ms
7,316 KB
testcase_34 AC 29 ms
7,384 KB
testcase_35 AC 28 ms
7,264 KB
testcase_36 AC 2 ms
5,468 KB
testcase_37 AC 1 ms
6,116 KB
testcase_38 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

typedef struct List {
	struct List *next;
	int v;
} list;

void chmax(int* a, int b)
{
	if (*a < b) *a = b;
}

int main()
{
	int i, N, u, w;
	list *adj[100001] = {}, e[200001], *p;
	scanf("%d", &N);
	for (i = 0; i < N - 1; i++) {
		scanf("%d %d", &u, &w);
		e[i*2].v = w;
		e[i*2+1].v = u;
		e[i*2].next = adj[u];
		e[i*2+1].next = adj[w];
		adj[u] = &(e[i*2]);
		adj[w] = &(e[i*2+1]);
	}
	
	int par[100001] = {}, q[100001], head, tail;
	par[1] = 1;
	q[0] = 1;
	for (head = 0, tail = 1; head < tail; head++) {
		u = q[head];
		for (p = adj[u]; p != NULL; p = p->next) {
			w = p->v;
			if (par[w] == 0) {
				par[w] = u;
				q[tail++] = w;
			}
		}
	}
	
	int dp[2][100001] = {}, tmp[2];
	for (head--; head > 0; head--) {
		u = q[head];
		tmp[0] = 0;
		tmp[1] = 0;
		chmax(&(tmp[0]), dp[0][par[u]] + dp[0][u]);
		chmax(&(tmp[0]), dp[0][par[u]] + dp[1][u]);
		chmax(&(tmp[1]), dp[1][par[u]] + dp[0][u]);
		chmax(&(tmp[1]), dp[1][par[u]] + dp[1][u]);
		chmax(&(tmp[1]), dp[0][par[u]] + dp[0][u] + 1);
		dp[0][par[u]] = tmp[0];
		dp[1][par[u]] = tmp[1];
	}
	printf("%d\n", (dp[0][1] > dp[1][1])? dp[0][1]: dp[1][1]);
	fflush(stdout);
	return 0;
}
0