Draughts

All submissions for this problem are available.
Read problems statements in Mandarin Chinese and Russian.
Furik and Rubik have come to the sanatorium, which consists of N rooms and M passageways. Each passageway connects two rooms, and there is at most one way to move between each pair of rooms. Some rooms have opened windows. There is a draught between two different rooms if both rooms have opened windows, and are connected with each other by some way.
Furik is interested in one question: what is the number of pairs of rooms, which have a draught between them. Rubik wants to know what is the number of the rooms, which have at least one draught passing through the room.
Input
The first line contains two spaceseparated integers N and M. The next line contains N integers, where the i^{th} number is equal to 1, if the window in the room number i is opened, otherwise 0. Then the next M lines contain pairs of integers, where the i^{th} pair denotes the numbers of the connected rooms by i^{th} passageway. Consider that the rooms are numerated by different integers from 1 to N.
Output
In a single line print two numbers, denoting the answers to Furik and Rubik questions.
Constraints
 1 ≤ N ≤ 50000 (5 × 10^{4})
 0 ≤ M ≤ N − 1
 There is at most one way to move between each pair of rooms, that is, the given graph is a forest
Example
Input: 6 5 1 1 1 1 1 0 1 2 1 6 1 5 2 4 4 3 Output: 10 5 Input: 2 1 1 0 1 2 Output: 0 0
Author:  sereja 
Tester:  gerald 
Editorial  http://discuss.codechef.com/problems/DRGHTS 
Tags  easy, feb14, sereja 
Date Added:  15062013 
Time Limit:  1 sec 
Source Limit:  50000 Bytes 
Languages:  C, CPP14, JAVA, PYTH, PYTH 3.6, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, PYP3, CLOJ, FS 
Comments
 Please login at the top to post a comment.
SUCCESSFUL SUBMISSIONS
Fetching successful submissions
HELP
If you are still having problems, see a sample solution here. 