//
// main.cpp
// Codechef Draught
//
// Created by Himanshu on 24/08/21.
//
#include <iostream>
#include <vector>
using namespace std;
long long tmp = 0;
void dfs(int x, vector<int> graph[], int vis[], int window[], long long &cPath, long long &cNode) {
tmp++;
vis[x] = 1;
// Set tmp = 0, and add the number of paths(tmp) between
// two rooms having a window each
if (window[x] == 1) {
cNode++;
cPath += tmp;
tmp = 0;
}
for (int i=0; i<graph[x].size(); i++) {
int j = graph[x][i];
if (vis[j] == 0) {
dfs(j, graph, vis, window, cPath, cNode);
}
}
// Backtracking and removing previously visited
// node from Rubik's answer
tmp--;
if (tmp < 0) {
tmp = 0;
}
}
int solve (vector<int> graph[], int window[], int n) {
int vis[n+1];
long long ansF = 0, ansR = 0, cPath = 0, cNode = 0;
for (int i=1; i<=n; i++) {
vis[i] = 0;
}
for (int i=1; i<=n; i++) {
cNode = 0;
cPath = 0;
//Performing DFS on each tree, starting from a room
// having a window
if (vis[i] == 0 && window[i] == 1){
dfs(i, graph, vis, window, cPath, cNode);
ansF += (cNode*(cNode-1))/2;
if (cPath > 1) {
ansR += cPath;
}
}
}
cout<<ansF<<" "<<ansR<<endl;
return 0;
}
int main () {
int n = 0, m = 0;
cin>>n>>m;
int window[n+1];
vector<int> graph[n+1];
int connect[m+1][2];
for (int i=1; i<=n; i++) {
cin>>window[i];
}
for (int i=1; i<=m; i++) {
cin>>connect[i][0]>>connect[i][1];
graph[connect[i][0]].push_back(connect[i][1]);
graph[connect[i][1]].push_back(connect[i][0]);
}
solve(graph, window, n);
return 0;
}
Ly8KLy8gIG1haW4uY3BwCi8vICBDb2RlY2hlZiBEcmF1Z2h0Ci8vCi8vICBDcmVhdGVkIGJ5IEhpbWFuc2h1IG9uIDI0LzA4LzIxLgovLwogCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHZlY3Rvcj4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKbG9uZyBsb25nIHRtcCA9IDA7CiAKdm9pZCBkZnMoaW50IHgsIH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jTm9kZSA9IDA7CiAgICAgICAgY1BhdGggPSAwOwogICAgICAgIC8vUGVyZm9ybWluZyBERlMgb24gZWFjaCB0cmVlLCBzdGFydGluZyBmcm9tIGEgcm9vbSAKICAgICAgICAvLyBoYXZpbmcgYSB3aW5kb3cKICAgICAgICBpZiAodmlzW2ldID09IDAgJiYgd2luZG93W2ldID09IDEpewogICAgICAgICAgICBkZnMoaSwgZ3JhcGgsIHZpcywgd2luZG93LCBjUGF0aCwgY05vZGUpOwogICAgICAgICAgICBhbnNGICs9IChjTm9kZSooY05vZGUtMSkpLzI7CiAgICAgICAgICAgIGlmIChjUGF0aCA+IDEpIHsKICAgICAgICAgICAgICAgIGFuc1IgKz0gY1BhdGg7CiAgICAgICAgICAgIH0KICAgICAgICB9CiAgICB9CiAgICBjb3V0PDxhbnNGPDwiICI8PGFuc1I8PGVuZGw7CiAgICByZXR1cm4gMDsKfQogCmludCBtYWluICgpIHsKICAgIGludCBuID0gMCwgbSA9IDA7CiAgICBjaW4+Pm4+Pm07CiAgICBpbnQgd2luZG93W24rMV07CiAgICB2ZWN0b3I8aW50PiBncmFwaFtuKzFdOwogICAgaW50IGNvbm5lY3RbbSsxXVsyXTsKICAgICAKICAgIGZvciAoaW50IGk9MTsgaTw9bjsgaSsrKSB7CiAgICAgICAgY2luPj53aW5kb3dbaV07CiAgICB9CiAgICBmb3IgKGludCBpPTE7IGk8PW07IGkrKykgewogICAgICAgIGNpbj4+Y29ubmVjdFtpXVswXT4+Y29ubmVjdFtpXVsxXTsKICAgICAgICBncmFwaFtjb25uZWN0W2ldWzBdXS5wdXNoX2JhY2soY29ubmVjdFtpXVsxXSk7CiAgICAgICAgZ3JhcGhbY29ubmVjdFtpXVsxXV0ucHVzaF9iYWNrKGNvbm5lY3RbaV1bMF0pOwogICAgfQogICAgIAogICAgc29sdmUoZ3JhcGgsIHdpbmRvdywgbik7CiAgICAgCiAgICByZXR1cm4gMDsKfQ==