/+ dub.sdl:
    name "A"
    dependency "dcomp" version=">=0.4.0"
+/

import std.stdio, std.algorithm, std.conv, std.range;
import std.typecons;

// import dcomp.scanner;

int main() {
    auto sc = new Scanner(stdin);
    alias E = Tuple!(int, "to");
    int n;
    sc.read(n);
    E[][] g = new E[][2*n-1];
    foreach (i; 0..n-1) {
        int a, b;
        sc.read(a, b); a--; b--;
        g[a] ~= E(n+i);
        g[n+i] ~= E(a);
        g[b] ~= E(n+i);
        g[n+i] ~= E(b);
    }
    string s;
    sc.read(s);

    n = 2*n-1;
    int[2] searchMid() {
        int[] rt = new int[n];
        int[2] lng;
        void dfs(int p, int b, int dps = 0) {
            rt[p] = b;
            if (lng[1] < dps) {
                lng = [p, dps];
            }
            foreach (e; g[p]) {
                int d = e.to;
                if (d == b) continue;
                dfs(d, p, dps+1);
            }
        }
        lng = [-1, -1];
        dfs(0, -1);
        int v = lng[0];
        lng = [-1, -1];
        dfs(v, -1);
        int[] path;
        int u = lng[0];
        while (u != v) {
            path ~= u;
            u = rt[u];
        }
        path ~= v;
//        writeln(path);
        return [path[path.length/2], path.length.to!int/2];
    }

    int[2] mid = searchMid();
//    writeln(mid);

    bool[] bc = new bool[n];
    bool[] bsm = new bool[n];
    void dfs(int p, int b) {
        if (p < (n+1)/2 && s[p] == '1') bc[p] = true;
        bsm[p] = bc[p];
        foreach (e; g[p]) {
            int d = e.to;
            if (d == b) continue;
            dfs(d, p);
            bsm[p] |= bsm[d];
        }
    }
    dfs(mid[0], -1);
    long ans = 0;
    long calc(int p, int b, int dps) {
        if (!bsm[p]) return 0;
        long sm = 1;
        if (bc[p]) {
            sm += dps/2;
        }
        foreach (e; g[p]) {
            int d = e.to;
            if (d == b) continue;
            sm += calc(d, p, dps-1);
        }
        return sm;
    }
    writeln(calc(mid[0], -1, mid[1]));

    return 0;
}
/* IMPORT /home/yosupo/Program/dcomp/source/dcomp/scanner.d */
// module dcomp.scanner;

class Scanner {
    import std.stdio : File;
    import std.conv : to;
    import std.range : front, popFront, array, ElementType;
    import std.array : split;
    import std.traits : isSomeChar, isStaticArray, isArray; 
    import std.algorithm : map;
    File f;
    this(File f) {
        this.f = f;
    }
    string[] buf;
    private bool succ() {
        while (!buf.length) {
            if (f.eof) return false;
            buf = f.readln.split;
        }
        return true;
    }
    private bool readSingle(T)(ref T x) {
        if (!succ()) return false;
        static if (isArray!T) {
            alias E = ElementType!T;
            static if (isSomeChar!E) {
                //string or char[10] etc
                x = buf.front;
                buf.popFront;
            } else {
                static if (isStaticArray!T) {
                    //static
                    assert(buf.length == T.length);
                }
                x = buf.map!(to!E).array;
                buf.length = 0;                
            }
        } else {
            x = buf.front.to!T;
            buf.popFront;            
        }
        return true;
    }
    int read(T, Args...)(ref T x, auto ref Args args) {
        if (!readSingle(x)) return 0;
        static if (args.length == 0) {
            return 1;
        } else {
            return 1 + read(args);
        }
    }
}

unittest {
    import std.path : buildPath;
    import std.file : tempDir;
    import std.algorithm : equal;
    import std.stdio : File;
    string fileName = buildPath(tempDir, "kyuridenanmaida.txt");
    auto fout = File(fileName, "w");
    fout.writeln("1 2 3");
    fout.writeln("ab cde");
    fout.writeln("1.0 1.0 2.0");
    fout.close;
    Scanner sc = new Scanner(File(fileName, "r"));
    int a;
    int[2] b;
    char[2] c;
    string d;
    double e;
    double[] f;
    sc.read(a, b, c, d, e, f);
    assert(a == 1);
    assert(equal(b[], [2, 3]));
    assert(equal(c[], "ab"));
    assert(equal(d, "cde"));
    assert(e == 1.0);
    assert(equal(f, [1.0, 2.0]));
}
