diff --git a/code_study/Baekjoon/c/30805.c b/code_study/Baekjoon/c/30805.c new file mode 100644 index 0000000..f18a768 --- /dev/null +++ b/code_study/Baekjoon/c/30805.c @@ -0,0 +1,75 @@ +#include +#include + +typedef struct { + int index, value; +} Pair; + +int comparator(const void* a, const void* b) { + Pair* A = (Pair*)a; + Pair* B = (Pair*)b; + + if(A->value == B->value) return A->index - B->index; + return B->value - A->value; +} + +int main() { + int N; + scanf("%d",&N); + Pair* pair_A = (Pair*)malloc(sizeof(Pair)*N); + + for(int i=0; i N ? M : N)); + int size = 0; + + while(idxA < N && idxB < M) { + int posA = pair_A[idxA].index, valA = pair_A[idxA].value; + int posB = pair_B[idxB].index, valB = pair_B[idxB].value; + + if(valA == valB) { + if(posA > limitA && posB > limitB) { + subsequence[size++] = valA; + idxA++; idxB++; + limitA = posA; + limitB = posB; + } + else if(posA <= limitA) idxA++; + else idxB++; + } + else if(valA > valB) idxA++; + else idxB++; + } + + printf("%d\n",size); + for(int i=0; i{ + int now,time; + + Tuple(int now, int time) { + this.now = now; + this.time = time; + } + + @Override + public int compareTo(Tuple other) { + return Integer.compare(this.time, other.time); + } +} + +public class _1238 { + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + int N = sc.nextInt(); + int M = sc.nextInt(); + int X = sc.nextInt(); + + @SuppressWarnings("unchecked") + ArrayList[] graph = new ArrayList[N+1]; + + @SuppressWarnings("unchecked") + ArrayList[] reverse_graph = new ArrayList[N+1]; + for(int i=0; i<=N; i++) { + graph[i] = new ArrayList(); + reverse_graph[i] = new ArrayList(); + } + + for(int i=0; i pq = new PriorityQueue<>(); + + // X -> N + pq.add(new Tuple(X, 0)); + int[] coming_time = new int[N+1]; + Arrays.fill(coming_time, Integer.MAX_VALUE); + coming_time[X] = 0; + + while(!pq.isEmpty()) { + Tuple current = pq.poll(); + + if(current.time > coming_time[current.now]) continue; + + for (Tuple next : graph[current.now]) { + if(coming_time[next.now] > current.time + next.time) { + coming_time[next.now] = current.time + next.time; + pq.add(new Tuple(next.now, coming_time[next.now])); + } + } + } + + // N -> X + pq.add(new Tuple(X, 0)); + int[] going_time = new int[N+1]; + Arrays.fill(going_time, Integer.MAX_VALUE); + going_time[X] = 0; + + while(!pq.isEmpty()) { + Tuple current = pq.poll(); + + if(current.time > going_time[current.now]) continue; + + for (Tuple next : reverse_graph[current.now]) { + if(going_time[next.now] > current.time + next.time) { + going_time[next.now] = current.time + next.time; + pq.add(new Tuple(next.now, going_time[next.now])); + } + } + } + + int maxTime = 0; + for(int i=1; i<=N; i++) { + maxTime = Math.max(maxTime, going_time[i] + coming_time[i]); + } + + System.out.println(maxTime); + } +}