This page is still under construction.

Parts of this page are still being built. What you see may change.

On Average They're Purple

Time limit1sMemory limit1024 MB

Summary
Alice two-colors the edges of a connected graph; Bob picks a 1 to N path minimizing color changes. Find the maximum number of color changes Alice can force.
Level

Medium7 of 10

Topics
Graph, BFS, Shortest path, Greedy
Solved
No attempts yet

Problem

Alice and Bob are playing a game on a simple connected graph with NN nodes and MM edges.

Alice colors each edge in the graph red or blue.

A path is a sequence of edges where each pair of consecutive edges have a node in common. If the first edge in the pair is of a different color than the second edge, then that is a "color change."

After Alice colors the graph, Bob chooses a path that begins at node 11 and ends at node NN. He can choose any path on the graph, but he wants to minimize the number of color changes in the path. Alice wants to choose an edge coloring to maximize the number of color changes Bob must make. What is the maximum number of color changes she can force Bob to make, regardless of which path he chooses?

Input

The first line contains two integer values NN and MM with 2≤N≤100 0002 \le N \le 100\,000 and 1≤M≤100 0001 \le M \le 100\,000. The next MM lines contain two integers a_ia\_i and b_ib\_i indicating an undirected edge between nodes a_ia\_i and b_ib\_i (1≤a_i,b_i≤N1 \le a\_i, b\_i \le N, a_i≠b_ia\_i \not= b\_i).

All edges in the graph are unique.

Output

Output the maximum number of color changes Alice can force Bob to make on his route from node 11 to node NN.

Examples2

  1. Example 1

    Input
    3 3
    1 3
    1 2
    2 3
    
    Expected output
    0
    
  2. Example 2

    Input
    7 8
    1 2
    1 3
    2 4
    3 4
    4 5
    4 6
    5 7
    6 7
    
    Expected output
    3