From c7f43cf7bcfaebf65b47c981dacbe4e56e34f5ec Mon Sep 17 00:00:00 2001 From: Sanghun Park Date: Sun, 28 Sep 2025 18:46:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]:=20BOJ2606=20=EB=B0=94=EC=9D=B4?= =?UTF-8?q?=EB=9F=AC=EC=8A=A4=20=EA=B5=AC=ED=98=84(DFS)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Devil_C/week04_dfs/sanghun/BOJ_2606.c | 49 +++++++++++++++++++++++++++ Devil_C/week04_dfs/sanghun/filename.c | 0 2 files changed, 49 insertions(+) create mode 100644 Devil_C/week04_dfs/sanghun/BOJ_2606.c delete mode 100644 Devil_C/week04_dfs/sanghun/filename.c diff --git a/Devil_C/week04_dfs/sanghun/BOJ_2606.c b/Devil_C/week04_dfs/sanghun/BOJ_2606.c new file mode 100644 index 0000000..754525d --- /dev/null +++ b/Devil_C/week04_dfs/sanghun/BOJ_2606.c @@ -0,0 +1,49 @@ +#include +#include + +struct virus{ + int node; + struct virus* next; +}; + +struct virus* graph[101]; + +void network(int u, int v){ + struct virus *vir; + vir = (struct virus*)malloc(sizeof(struct virus)); + vir -> node = v; + vir -> next = graph[u]; + graph[u] = vir; +} + +int visited[101]; +int count = 0; +void dfs(int start){ + visited[start] = 1; + count ++; + struct virus* current = graph[start]; + while(current != NULL){ + if(!visited[current -> node]){ + dfs(current -> node); + } + current = current -> next; + } + return; +} + +int main(){ + int com; + int num; + scanf("%d %d", &com, &num); + + for(int i=0; i Date: Sun, 28 Sep 2025 20:18:53 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[feat]:=20BOJ17220=20=EB=A7=88=EC=95=BD?= =?UTF-8?q?=EC=88=98=EC=82=AC=EB=8C=80=20=ED=92=80=EC=9D=B4(DFS)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Devil_C/week04_dfs/sanghun/BOJ_17220.c | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Devil_C/week04_dfs/sanghun/BOJ_17220.c diff --git a/Devil_C/week04_dfs/sanghun/BOJ_17220.c b/Devil_C/week04_dfs/sanghun/BOJ_17220.c new file mode 100644 index 0000000..38866b8 --- /dev/null +++ b/Devil_C/week04_dfs/sanghun/BOJ_17220.c @@ -0,0 +1,65 @@ +#include +#include + +struct supply { + int cur; + struct supply *next; +}; + +struct supply *graph[128]; +int visited[128]; +int deleted[128]; +int indegree[128]; +int count = 0; + +void con(int u, int v) { + struct supply *sup = (struct supply*)malloc(sizeof(struct supply)); + sup->cur = v; + sup->next = graph[u]; + graph[u] = sup; + indegree[v]++; +} + +void dfs(int start) { + if (visited[start] || deleted[start]) return; + visited[start] = 1; + count++; + + struct supply *current = graph[start]; + while (current != NULL) { + if (!visited[current->cur] && !deleted[current->cur]) { + dfs(current->cur); + } + current = current -> next; + } +} + +int main() { + int n, m; + scanf("%d %d", &n, &m); + + for (int i = 0; i < m; i++) { + char u, v; + scanf(" %c %c", &u, &v); + con(u, v); + } + + int k; + scanf("%d", &k); + for (int i = 0; i < k; i++) { + char d; + scanf(" %c", &d); + deleted[d] = 1; + } + int origin = 0; + + for (int i = 'A'; i < 'A' + n; i++) { + if (!deleted[i] && (indegree[i] == 0)) { + dfs(i); + origin ++; + } + } + + printf("%d", count - origin); + return 0; +}