-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1557.c
More file actions
43 lines (41 loc) · 1.01 KB
/
1557.c
File metadata and controls
43 lines (41 loc) · 1.01 KB
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
#include <stdio.h>
#include <stdlib.h>
int* findSmallestSetOfVertices(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize){
int *ind = calloc(n, sizeof(int));
int count = 0, i;
for(i = 0; i < edgesSize; i++) {
ind[edges[i][1]]++;
}
for(i = 0; i < n; i++) {
if(ind[i] == 0){
ind[count++] = i;
} /*else {
ind[i]=0;
}*/
}
*returnSize = count;
return ind;
}
/*
Best Solution
int* findSmallestSetOfVertices(int n, int** edges, int edgesSize, int* edgesColSize, int* returnSize) {
int* indegree = calloc(n, sizeof(int));
int i, j, count = 0;
for (i = 0; i < edgesSize; i++) {
indegree[edges[i][1]]++;
}
for (i = 0; i < n; i++) {
if (indegree[i] == 0) count++;
}
int* res = malloc(count * sizeof(int));
j = 0;
for (i = 0; i < n; i++) {
if (indegree[i] == 0) {
res[j++] = i;
}
}
*returnSize = count;
free(indegree);
return res;
}
*/