#include <bits/stdc++.h>   using namespace std;   template <class T>   void printQueue(T& q) {     while (!q.empty()) {       cout << q.top() << endl;       q.pop();     }   }   vector<int> adj[200009];   vector<pair<int, int> > levels;   bool visited[200009];   bool cmp(pair<int, int> a, pair<int, int> b) {     if (a.first == b.first) {       return a.second < b.second;     } else {       return a.first > b.first;     }   }   void dfs(int s, int level) {     visited[s] = true;     levels.push_back(make_pair(level, s));     for (int i = 0; i < adj[s].size(); i++) {       if (visited[adj[s][i]] == false) {         dfs(adj[s][i], level + 1);       }     }   }   int main() {     int t = 1;     while (t--) {       int n, x;       cin >> n;       long long dp[n + 1][2];       memset(dp, 0, sizeof(dp));       for (int i = 1; i < n; i++) {         cin >> x;         adj[x].push_back(i);         adj[i].push_back(x);       }       dfs(1, 1);       for (int j = 0; j < n; j++) {         cin >> x;         if (x == 1) {           dp[j][0] = 1;           dp[j][1] = 0;         } else {           dp[j][0] = 0;           dp[j][1] = 1;         }       }       sort(levels.begin(), levels.end(), cmp);       bool visit[n + 1];       memset(visit, false, sizeof(visit));       int index;       for (int i = 0; i < levels.size(); i++) {         visit[levels[i].second] = true;         index = levels[i].second;         for (int j = 0; j < adj[index].size(); j++) {           if (visit[adj[index][j]] == false) {             dp[adj[index][j]][0] =                 ((dp[index][0] * dp[adj[index][j]][0]) % 1000000007ll) +                 ((dp[index][0] * dp[adj[index][j]][1]) % 1000000007ll) +                 ((dp[index][1] * dp[adj[index][j]][0]) % 1000000007ll);             dp[adj[index][j]][0] %= 1000000007ll;             dp[adj[index][j]][1] =                 ((dp[index][0] * dp[adj[index][j]][1]) % 1000000007ll) +                 ((dp[index][1] * dp[adj[index][j]][1]) % 1000000007ll);             dp[adj[index][j]][1] %= 1000000007ll;           }         }       }       cout << dp[1][0] << endl;     }   }   