#include <bits/stdc++.h>

using namespace std;

int minDistance(int n, int dist[], bool sptSet[])
{
    int min = INT_MAX, min_index;

    for (int v = 0; v < n; v++)
        if (sptSet[v] == false && dist[v] <= min)
            min = dist[v], min_index = v;

    return min_index;
}

void printSolution(int n, int dist[])
{
    printf("Vertex \t\t Distance from Source\n");
    for (int i = 0; i < n; i++)
        printf("%d \t\t %d\n", i, dist[i]);
}

int main()
{
   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    scanf("%d",&n);
    char graf[n][n];

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            graf[i][j] = 'X';
        }
    }

    for(int z=0;z<n-1;z++){
        int u,v;
        char x;
        cin >> u >> v >> x;
        graf[u-1][v-1]=x;
        graf[v-1][u-1]=x;
    }

    //vector<pair<int,int>> parovi;
    int br=0;

    for(int i=0;i<n;i++){
        int dist[n];
        bool sptSet[n];

        for (int i = 0; i < n; i++)
            dist[i] = INT_MAX, sptSet[i] = false;

        dist[i] = 0;

        for (int count = 0; count < n - 1; count++) {
            int u = minDistance(n,dist, sptSet);

            sptSet[u] = true;

            for (int v = 0; v < n; v++)

                if (!sptSet[v] && graf[u][v]!='X' && dist[u] != INT_MAX
                    && dist[u] + graf[u][v] < dist[v])
                    dist[v] = dist[u] + graf[u][v];
        }

        for(int z=0;z<n;z++)
            if(dist[z]==235)
                br++;
                //parovi.push_back(make_pair(i,z));

            }

            printf("%d",br/2);
            /*
            for(int i=0;i<parovi.size();i++){
                printf("%d - %d\n",parovi[i].first, parovi[i].second);
            }
            */

    return 0;
}