import java.util.*;
import java.lang.*;
import java.io.*;


class Main {
     static Node[] node_arr;
     static int arr_size;
        
    static class Node {
        int from;
        int to;
        Node(int from, int to) {
            this.from = from;
            this.to = to;
        }
    }

    

    public static void push(int idx) {
        int a = Node.from;
        int b = Node.from;
        while (idx != 0) {
            int parent_idx = (idx-1)/2;
            if(node_arr[parent_idx.from] > node_arr[idx.from]) {
                swap(node_arr[parent_idx.from], node_arr[idx.from]);
                idx = parent_idx;
            } else {
                break;
            }
            
        }
    }

    public static int pop() {
        int num = node_arr[0];
        node_arr[0] = node_arr[arr_size-1];
        int idx = 0;
        while (true) {
            int left = idx*2 + 1;
            int right = idx*2 + 2;
            int smallest = idx;
            if(left <= arr_size-1 && node_arr[left].from < node_arr[smallest].from) {
                smallest = left;
            }
            if (right <= arr_size-1&& node_arr[right].from < node_arr[smallest].from) {
                smallest = right;
            }
            if (smallest == idx) break; 

            idx = smallest
        }
    }

    

    void swap(int parent, int child) {
        int temp = node_arr[parent];
        node_arr[parent] = node_arr[child];
        node_arr[child] = temp;        
    }

    
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());

        node_arr = new Node[M+1];
        arr_size = 0;
         for (int i=0; i<M; i++) {
            arr_size++;
            st = new StringTokenizer(br.readLine());
            int A = Integer.parseInt(st.nextToken());
            int B = Integer.parseInt(st.nextToken());
            
            push(i);
        }
        
        System.out.println(pq);
        
        
    }
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: