8 typedef struct node node
;
9 typedef struct neighbor neighbor
;
18 node nodes
[2000]; // cheat, by pre-inspecting input file
26 while ((nread
= getline(&line
, &len
, stdin
)) >= 0) {
29 if (strtol (p
, &e
, 10) != count
)
31 if (strncmp (e
, " <-> ", 5))
36 int n
= strtol (p
, &e
, 10);
37 neighbor
*next
= calloc (1, sizeof *next
);
39 next
->next
= nodes
[count
].next
;
40 nodes
[count
].next
= next
;
45 printf ("parsed connections for %d nodes\n", count
);
49 for (i
= 0; i
< count
; i
++)
55 nodes
[i
].group
= ++groups
;
58 for (i
= 0; i
< count
; i
++) {
59 if (nodes
[i
].group
!= groups
)
61 for (neighbor
*next
= nodes
[i
].next
; next
; next
= next
->next
)
62 if (!nodes
[next
->n
].group
)
63 changed
= (nodes
[next
->n
].group
= groups
);
68 for (i
= 0; i
< count
; i
++)
69 if (nodes
[i
].group
== 1)
71 printf ("node 0 among group of %d nodes\n", size
);
72 printf ("total of %d groups\n", groups
);