아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Autobiography

시간 제한1초메모리 제한1024 MB

요약
무방향 그래프에서 색이 b-o-b-o 순서가 되는 서로 다른 네 정점의 경로 순서쌍을 센다.
난이도

보통10점 중 6점

유형
그래프, 조합론, 해시맵
정답자
아직 제출이 없습니다

문제

Bobo has an undirected graph with nn vertices and mm edges. The vertices are numbered by 1,…,n1, \dots, n, and the ii-th edge is between the a_ia\_i-th and the b_ib\_i-th vertex. Plus, the ii-th vertex is associated with a character c_ic\_i.

Find the number of ways to choose four distinct vertices (u,v,w,x)(u, v, w, x) such that

  • uu and vv, vv and ww, ww and xx are connected by an edge,
  • c_u=bc\_u = \mathtt{b}, c_v=oc\_v = \mathtt{o}, c_w=bc\_w = \mathtt{b}, c_x=oc\_x = \mathtt{o}.

입력

The input consists of several test cases terminated by end-of-file. For each test case,

The first line contains two integers nn and mm.

The second line contains nn characters c_1…c_nc\_1 \dots c\_n.

For the following mm lines, the ii-th line contains two integers a_ia\_i and b_ib\_i.

출력

For each test case, output an integer which denotes the number of ways.

제한

  • 4≤n≤2×1054 \le n \le 2 \times 10^5
  • 0≤m≤2×1050 \le m \le 2 \times 10^5
  • c_i∈b,oc\_i \in \\{\mathtt{b}, \mathtt{o}\\} for each 1≤i≤n1 \leq i \leq n
  • 1≤a_i,b_i≤n1 \leq a\_i, b\_i \leq n for each 1≤i≤m1 \leq i \leq m
  • a_i≠b_ia\_i \neq b\_i for each 1≤i≤m1 \leq i \leq m
  • a_i,b_i≠a_j,b_j\\{a\_i, b\_i\\} \neq \\{a\_j, b\_j\\} for each 1≤i<j≤m1 \leq i < j \leq m
  • In each input, the sum of nn does not exceed 2×1052 \times 10^5. The sum of mm does not exceed 2×1052 \times 10^5.

힌트

For the first test case, there are 22 quadrangles (1,3,4,5)(1, 3, 4, 5), (2,3,4,5)(2, 3, 4, 5).

For the second test case, there are 44 quadrangles (1,2,3,4)(1, 2, 3, 4), (1,4,3,2)(1, 4, 3, 2), (3,2,1,4)(3, 2, 1, 4), (3,4,1,2)(3, 4, 1, 2).

For the third test case, there are no valid quadrangles.

예제1

  1. 예제 1

    입력
    5 4
    bbobo
    1 3
    2 3
    3 4
    4 5
    4 6
    bobo
    1 2
    1 3
    1 4
    2 3
    2 4
    3 4
    4 0
    bobo
    
    예상 출력
    2
    4
    0