Lang:GCC
Edit12345678910111213141516171819202122232425262728293031#include <stdio.h>#include <string.h>#define N (100000)struct edge {int nid;struct edge *next;};struct edge *nodes[N];struct edge edges[N << 1];struct edge *stack[N];int stack_max[N][2];int used[N];void add_edge(int src, int to, int eid){edges[eid].nid = to;edges[eid].next = nodes[src];nodes[src] = &edges[eid];}int main(){int n, i, a, b, nedge, top, len, max_path;scanf("%d", &n);for(i = 1, nedge = 0; i < n; i++) {scanf("%d%d", &a, &b);add_edge(--a, --b, nedge++);add_edge(b, a, nedge++);