結果
問題 | No.2532 Want Play More |
ユーザー | chro_96 |
提出日時 | 2023-11-03 22:49:59 |
言語 | C (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 1,115 bytes |
コンパイル時間 | 453 ms |
コンパイル使用メモリ | 29,440 KB |
実行使用メモリ | 21,360 KB |
最終ジャッジ日時 | 2024-09-25 21:13:06 |
合計ジャッジ時間 | 3,075 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
ソースコード
#include <stdio.h> typedef struct list { int v; struct list *n; } list; void func (int v, list **e, int *visited, int ans[][2]) { list *l = e[v]; visited[v] = 1; ans[v][0] = 0; ans[v][1] = 0; while (l != NULL) { if (visited[l->v] <= 0) { func(l->v, e, visited, ans); if (ans[v][0] < ans[l->v][1]+1) { ans[v][0] = ans[l->v][1]+1; } if (ans[v][1] <= 0 || ans[v][1] > ans[l->v][0]+1) { ans[v][1] = ans[l->v][0]+1; } } l = l->n; } return; } int main () { int n = 0; int a = 0; int b = 0; int res = 0; int ans[200000][2] = {}; list *e[200000] = {}; list pool[399998] = {}; int used = 0; int visited[200000] = {}; res = scanf("%d", &n); for (int i = 0; i < n-1; i++) { res = scanf("%d", &a); res = scanf("%d", &b); a--; b--; pool[used].v = b; pool[used].n = e[a]; e[a] = pool+used; used++; pool[used].v = a; pool[used].n = e[b]; e[b] = pool+used; used++; } func(0, e, visited, ans); printf("%d\n%d\n", ans[0][0], ans[0][1]); return 0; }