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: Wrong Answer)

package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,100)}
  n,m := input.NextInts()
  g := make([][]int,n)
  for i:=0;i<m;i++ {
    u,v := input.NextInts()
    g[u-1] = append(g[u-1],v-1)
    g[v-1] = append(g[v-1],u-1)
  }
  fmt.Println(multiply(g,g))
}

func multiply(ga,gb [][]int) int64 {
  na,ia,pa,qa := decompose(ga)
  nb,ib,pb,qb := decompose(gb)
  return int64(ia)*int64(ib)+int64(ia)*int64(nb-ib)+int64(ib)*int64(na-ia)+
  int64(pa)*int64(pb)+int64(pa)*int64(qb)+int64(qa)*int64(pb)+
  2*int64(qa)*int64(qb)
}

func decompose(g [][]int) (int,int,int,int) {
  n,i,p,q := len(g),0,0,0
  used := make([]bool,n)
  color := make([]int,n)
  var isBipartite func(int) bool
  isBipartite = func(u int) bool {
    if color[u] == 0 {
      color[u] = 1
      return isBipartite(u)
    }
    used[u] = true
    ret := true
    for _,v := range g[u] {
      if color[v] == color[u] { return false }
      if color[v] == 0 {
        color[v] = -color[u]
        ret = isBipartite(v) && ret
      }
    }
    return ret
  }
  for u:=0;u<n;u++ {
    if used[u] { continue }
    used[u] = true
    if len(g[u]) == 0 { i++;continue }
    if isBipartite(u) { q++;continue }
    p++
  }
  return n,i,p,q
}

type Input struct { reader *bufio.Reader }
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInts() (int,int) {
  s := strings.Fields(i.NextLine())
  x,_ := strconv.Atoi(s[0])
  y,_ := strconv.Atoi(s[1])
  return x,y
}