Problem:
Score : 800 points

Problem Statement

Takahashi has received an undirected graph with N vertices, numbered 1, 2, ..., N.
The edges in this graph are represented by (u_i, v_i).
There are no self-loops and multiple edges in this graph.

Based on this graph, Takahashi is now constructing a new graph with N^2 vertices, where each vertex is labeled with a pair of integers (a, b) (1 \leq a \leq N, 1 \leq b \leq N).
The edges in this new graph are generated by the following rule:

Span an edge between vertices (a, b) and (a', b') if and only if both of the following two edges exist in the original graph: an edge between vertices a and a', and an edge between vertices b and b'.

How many connected components are there in this new graph?

Constraints

2 \leq N \leq 100,000

0 \leq M \leq 200,000

1 \leq u_i < v_i \leq N

There exists no pair of distinct integers i and j such that u_i = u_j and v_i = v_j.

Input

The input is given from Standard Input in the following format:

N M
u_1 v_1
u_2 v_2
:
u_M v_M

Output

Print the number of the connected components in the graph constructed by Takahashi.

Sample Input 1

3 1
1 2

Sample Output 1

7

The graph constructed by Takahashi is as follows.

Sample Input 2

7 5
1 2
3 4
3 5
4 5
2 6

Sample Output 2

18

Solution in Go (1.6) (judge verdict: Time Limit Exceeded)

package main

import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}

func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

func Find(R *[]int, u int) int {
  if (*R)[u] == u { return u }
  (*R)[u] = Find(R, (*R)[u])
  return (*R)[u]
}
func Union(R *[]int, u, v int) {
  ru, rv := Find(R, u), Find(R, v)
  if ru < rv {
    (*R)[rv] = ru
  } else if rv < ru {
    (*R)[ru] = rv
  }
}

func Bipartite(G [][]int, u int) bool {
  N := len(G)
  D := make([]int, N)
  for i := range D {
    D[i] = -1
  }
  D[u] = 0
  Q := make([]int, N)
  for i := range Q {
    Q[i] = -1
  }
  Q[0] = u
  pos := 1
  for _, q := range Q {
    if q < 0 { break }
    for _, adj := range G[q] {
      if D[adj] < 0 {
        D[adj] = 1 - D[q]
        Q[pos] = adj
        pos++
      } else if D[q] == D[adj] {
        return false
      }
    }
  }
  return true
}

func Solve() {
  var N, M int
  NextInt(&N, &M)
  G := make([][]int, N)
  for i := range G {
    G[i] = make([]int, 0)
  }
  R := make([]int, N)
  for i := range R {
    R[i] = i
  }
  var a, b int
  for i := 0; i < M; i++ {
    NextInt(&a, &b)
    a, b = a - 1, b - 1
    G[a] = append(G[a], b)
    G[b] = append(G[b], a)
    Union(&R, a, b)
  }
  U := make([]int, N)
  for i := range R {
    U[Find(&R, i)]++
  }
  C := make([]int, 3)
  for i, u := range U {
    if u == 0 { continue }
    if u == 1 {
      C[0]++
    } else if Bipartite(G, i) {
      C[1]++
    } else {
      C[2]++
    }
  }
  Write((2 * N - C[0]) * C[0] + 2 * (C[1] + C[2]) * C[1] + C[2] * C[2])
}

func main() {
  Solve()
  Output()
}