diff --git a/code_study/Baekjoon/c/1167.c b/code_study/Baekjoon/c/1167.c new file mode 100644 index 0000000..a93721c --- /dev/null +++ b/code_study/Baekjoon/c/1167.c @@ -0,0 +1,97 @@ +#include +#include +#include + +typedef struct Edge { + int to; + int weight; + struct Edge* next; +} edge; + +typedef struct { + int now; + int distance; +} tuple; + +void add_edge(edge** graph, int u, int v, int w); +tuple find_maxLength_node(int start, edge** graph, int v); + +int main() { + int V; + scanf("%d",&V); + + edge** graph = (edge**)malloc(sizeof(edge*)*(V+1)); + + for(int i=0; inext; + free(temp); + } + } + + free(graph); + return 0; +} + +void add_edge(edge** graph, int u, int v, int w) { + edge* new_edge = (edge*)malloc(sizeof(edge)); + new_edge -> to = v; + new_edge -> weight = w; + new_edge -> next = graph[u]; + graph[u] = new_edge; +} + +tuple find_maxLength_node(int start, edge** graph, int v) { + tuple result = {start, 0}; + bool* visited = (bool*)calloc(v+1,sizeof(bool)); + tuple* stack = (tuple*)malloc(sizeof(tuple)*v); + int top = -1; + + stack[++top] = result; + visited[start] = true; + + while(top != -1) { + tuple current = stack[top--]; + + if(result.distance < current.distance) result = current; + + edge* ptr = graph[current.now]; + while(ptr != NULL) { + if(!visited[ptr->to]) { + tuple next = {ptr->to, ptr->weight + current.distance}; + stack[++top] = next; + visited[ptr->to] = true; + } + ptr = ptr -> next; + } + } + + free(visited); + free(stack); + return result; +} \ No newline at end of file diff --git a/code_study/Baekjoon/python/2742.py b/code_study/Baekjoon/python/2742.py new file mode 100644 index 0000000..3c331d0 --- /dev/null +++ b/code_study/Baekjoon/python/2742.py @@ -0,0 +1 @@ +print('\n'.join(list(map(str,[n for n in range(int(input()),0,-1)])))) \ No newline at end of file