This repository has been archived by the owner on Jun 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
B_aditya_chopra.c
86 lines (64 loc) · 1.58 KB
/
B_aditya_chopra.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int visited[1000] = {0};
struct Node
{
int vertex;
struct Node* next;
};
struct Graph
{
int numVertices;
struct Node** adjList;
};
typedef struct Node Node;
typedef struct Graph Graph;
Node* createNode(int v) {
Node* node = (Node*)malloc(sizeof(Node));
node->vertex = v;
node->next = NULL;
return node;
}
Graph* createGraph(int vertices) {
Graph* graph = (Graph*)malloc(sizeof(Graph));
graph->numVertices = vertices;
graph->adjList = malloc(vertices * sizeof(Node*));
for (int i = 0; i < vertices; ++i) {
graph->adjList[i] = NULL;
}
return graph;
}
void addEdge(Graph* graph, int s, int d) {
Node* node = createNode(d);
node->next = graph->adjList[s];
graph->adjList[s] = node;
}
int DFS(Graph* graph, int start, int visited[1000], int *count) {
visited[start] = 1;
(*count)++;
for (Node* u = graph->adjList[start]; u != NULL; u = u->next) {
if (!visited[u->vertex]) {
DFS(graph, u->vertex, visited, count);
}
}
}
int main() {
uint32_t n, m, u, v, maxVisited = 0;
scanf("%d%*c%d", &n, &m);
Graph* grandLine = createGraph(n);
for (int i = 0; i < m; ++i) {
scanf("%d %d", &u, &v);
addEdge(grandLine, u - 1, v - 1);
}
for (uint32_t i = 0; i < n; i++)
{
uint32_t visited[1000] = {0}, count = 0;
DFS(grandLine, i, visited, &count);
if (count > maxVisited) {
maxVisited = count;
}
}
printf("%d", maxVisited);
return 0;
}