68 74
7 8
24 23
55 56
3 50
61 62
12 1
32 33
36 35
9 8
44 50
53 5
29 28
16 2
36 37
3 22
44 45
27 28
66 65
34 4
31 32
64 65
13 12
10 9
67 66
5 47
55 54
6 51
20 21
67 4
17 29
41 40
48 49
19 20
18 17
35 4
25 24
33 34
38 37
5 48
43 30
63 62
60 61
66 6
26 27
64 63
14 13
67 68
68 54
42 41
52 53
39 38
50 49
59 58
46 45
39 40
57 58
1 11
52 51
15 2
57 56
2 67
23 3
26 25
6 53
30 31
10 11
7 14
1 30
22 21
42 43
47 46
16 15
59 60
18 19
 8 9
1 6
3 6
4 7
8 1
1 5
8 4
2 7
3 5
8 2
 7 7
7 6
7 2
6 1
5 4
5 1
1 4
3 7
 17 20
13 11
2 3
16 3
12 14
17 1
2 6
5 4
7 9
3 10
8 16
10 8
14 2
6 15
1 7
15 1
15 12
4 13
8 5
9 17
11 5
 6 6
4 3
4 2
5 4
6 5
4 6
1 6
 4 4
1 2
2 3
1 3
1 4
 10 11
9 3
8 7
1 2
1 8
10 8
7 10
4 1
6 4
3 6
5 9
2 5
 1 0
 9 9
9 8
7 6
8 7
5 6
3 2
1 5
1 3
1 4
4 2
 2 1
1 2
 16 20
1 16
15 14
5 11
12 1
16 2
5 14
2 4
6 1
11 7
11 1
8 12
9 6
7 5
10 15
1 8
14 10
4 13
3 9
13 16
6 3
 7 8
7 4
3 1
2 1
6 5
6 7
2 3
1 4
4 5
 9 9
1 9
6 7
8 7
1 8
5 7
3 2
4 9
8 3
6 1
 11 12
6 5
7 1
1 2
2 11
10 11
9 6
8 7
4 8
11 9
2 3
5 10
3 4
 5 4
1 2
3 4
1 4
5 1
 8 8
6 7
5 1
8 2
3 1
6 4
3 6
7 4
8 5
 10 10
2 5
7 8
1 7
1 9
5 3
6 9
5 9
6 4
1 10
8 9
 4 3
3 4
2 4
4 1
 13 15
9 1
12 3
6 11
8 2
2 5
13 10
3 4
8 4
11 9
9 2
10 8
1 6
7 12
5 13
4 7
 11 12
11 1
9 3
6 1
6 7
2 10
4 6
9 11
10 9
10 11
1 8
6 5
8 7
 8 8
1 6
7 3
1 8
7 8
5 4
4 1
6 5
6 2
 3 3
2 1
1 3
3 2
 17 21
8 2
9 6
6 7
3 14
12 16
4 11
11 15
14 13
13 4
5 8
6 1
2 5
16 7
7 12
3 17
14 8
17 10
7 14
1 9
15 14
10 3
 3 2
1 2
2 3
 3 3
3 2
1 3
1 2
 10 9
9 8
4 10
8 7
1 3
8 3
7 6
7 5
10 9
2 7
 11 12
10 1
8 7
4 11
5 2
7 9
6 10
11 6
2 8
1 4
9 3
9 4
3 5
 18 22
5 3
15 18
8 10
17 6
9 2
7 16
7 10
3 8
11 9
2 14
4 18
10 5
14 11
11 13
1 4
13 7
15 6
16 17
6 12
18 1
12 15
17 13
 5 5
5 1
2 3
4 2
5 2
1 4
 8 8
3 1
4 5
6 1
7 8
2 5
3 2
1 4
6 8

22
16
19
16
15
13
26
26
25
24
23
23
24
25
17
17
25
24
23
22
21
20
20
21
22
23
24
25
26
21
20
19
18
17
17
18
19
20
21
22
23
23
22
19
18
17
16
16
17
18
14
15
14
17
18
19
20
21
21
20
19
18
17
16
15
14
15
16
 3
4
5
4
4
4
5
3
 3
4
4
4
4
2
3
 9
6
6
10
9
7
10
8
11
7
10
8
11
7
8
7
10
 3
3
3
2
2
2
 1
2
2
2
 3
3
5
3
4
4
5
4
5
5
 0
 5
7
6
6
4
4
5
6
7
 1
1
 4
6
6
7
5
5
5
5
6
7
4
5
6
6
7
5
 3
4
4
2
3
4
3
 3
5
4
5
5
4
4
3
4
 4
3
4
5
6
6
5
6
5
5
4
 2
3
3
2
3
 3
6
4
6
4
5
6
5
 3
4
4
4
3
3
4
3
2
4
 2
2
2
1
 6
4
6
5
5
7
6
4
5
5
6
7
5
 3
5
5
5
5
4
5
4
4
4
3
 3
5
5
4
5
4
4
3
 1
1
1
 5
5
4
5
5
4
3
4
5
5
5
4
4
3
4
4
5
 2
1
2
 1
1
1
 5
5
4
5
5
5
4
3
3
4
 5
6
4
4
5
6
4
5
3
6
5
 9
8
9
9
8
6
6
8
7
7
6
7
5
7
7
5
5
8
 3
2
3
2
2
 3
5
4
4
5
3
5
4

import java.util.*;

public class Test {
    public static void main(String[] args) {
        new Test(new Scanner(System.in));
    }

    class Graph {
        int N, M;

        ArrayList<Edge>[] adj;

        Graph(int NN) {
            M = 0;
            adj = new ArrayList[N=NN];
            for (int i = 0; i < N; i++)
                adj[i] = new ArrayList<>();

        }
        void add(int i, int j) {
            adj[i].add(new Edge(j, M));
            adj[j].add(new Edge(i, M));
            M++;
        }
    }

    class Edge {
        int j, id;

        Edge(int jj, int ii) {
            j=jj; id=ii;
        }
    }

    Graph g;
    Graph mst;
    int cnt;
    int[] pre, low, stk, dist;
    ArrayList<ArrayList<Integer>> comps;
    ArrayList<Integer> bridges;
    boolean[] art, used, edgeDel, visited, isLeaf;
    int count, x, maxCount;


    void dfs2(int i, int count) {

        visited[i] = true;
        count++;
        for(Edge e : mst.adj[i]) {
            if(!visited[e.j]) {
                if(count > maxCount) {
                    maxCount = count;
                    x = e.j;
                }
                dfs2(e.j, count);
            }
        }
    }

    int dfs(int i, int p, int id) {
        // Meet a back edge and base case to dfs
        if(!used[id]) {
            used[id] = true;
            stk[++stk[0]] = id; // Push onto a stack
        }

        // update Low Link
        if (pre[i] != -1) {
            low[p] = Math.min(low[p], pre[i]);
            edgeDel[id]=true;
            return low[p];
        }
        pre[i] = cnt++;
        low[i] = pre[i];
        boolean hasFwd = false;


        for(Edge e : g.adj[i]) {
            if(e.id == id) continue; // already explore this edge dont go back its a parallel arc

            if(dfs(e.j, i, e.id) < 0) {
                mst.add(i, e.j);
                low[i] = Math.min(low[i], low[e.j]);

                if(low[e.j] == pre[e.j]) {
                    bridges.add(e.id);
                }

                if(i != p ? low[e.j] >= pre[i] : hasFwd) {
                    art[i] = true;
                    makeComp(e.id).add(stk[stk[0]--] + 1);
                }

                hasFwd = true;
            }
        }

        return -1;
    }

    ArrayList<Integer> makeComp(int id) {
        ArrayList<Integer> comp = new ArrayList<>();

        while(stk[stk[0]] != id)
            comp.add(stk[stk[0]--]+1); // Pop of the stack

        comps.add(comp);
        return comp;
    }

    Test(Scanner in) {
        g = new Graph(in.nextInt());
        mst = new Graph(g.N);
        int M = in.nextInt();

        while(M-->0)
        {
            int i = in.nextInt()-1;
            int j = in.nextInt()-1;
            g.add(i, j);
        }
        used = new boolean[g.M+1];
        edgeDel = new boolean[g.M+1];
        pre = new int[g.N];
        visited = new boolean[g.N];
        low = new int[g.N];
        stk = new int[g.M+2];
        Arrays.fill(pre, -1);
        bridges = new ArrayList<>();
        art = new boolean[g.N];
        comps = new ArrayList<>();
        isLeaf = new boolean[g.M+1];
        dist = new int[g.N];
        count = 0;
        x = 0;

        for(int i=0; i<g.N; i++) {
            if(pre[i] == -1) {
                used[g.M] = false;
                dfs(i, i, g.M);

                if(stk[0] > 1)
                    makeComp(g.M);
                stk[0] = 0;
            }
        }

//        System.out.printf("Bridges are: %s%n", bridges);
//
//        System.out.println("-----------");

        ArrayList<Integer> arts = new ArrayList<>();
        for(int i=0; i<g.N; i++)
            if(art[i])
                arts.add(i);

//        System.out.printf("Art pts are: %s", arts);
//
//        System.out.printf("%n%d 2-vertex-connected compontents found:%n", comps.size());
//
//        for(ArrayList<Integer> comp : comps) {
//            System.out.println(comp);
//        }
//
//        for(int i=0; i<used.length; ++i) {
//            System.out.print(" " + edgeDel[i]);
//        }

        for(int i=0; i<mst.N; ++i) {
            if(mst.adj[i].size() == 1) {
                isLeaf[i] = true;
            }
        }

        for(int i=0; i<g.N; i++) {
            Arrays.fill(visited, false);
            maxCount = 0;
            count = 0;
            dfs2(i, count);

            if(isLeaf[i]) {
                dist[i] = maxCount - 1;
            } else {
                dist[i] = maxCount;
            }

        }

        for(int i=0; i<g.N; i++) {
            System.out.print(dist[i] + " ");
        }

    }
}


































































