using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication16
{
    class Program
    {
        static void Main(string[] args)
        {
            int i,j,k=0, br1 = 1, br2 = 0, br3 = 0, br = 0,x=0,y=0;
            int n = int.Parse(Console.ReadLine());
            int[] u = new int[n-1];
            int[] v = new int[n-1];
            string str = null;
            for (i = 0; i < n-1; i++)
            { 
                string[] c = Console.ReadLine().Split();
                u[i] = Int32.Parse(c[0]);
                v[i] = Int32.Parse(c[1]);
                str += c[2];
            }
            for (i = 0; i < n-1; i++)
            {
                for(j=0;j<n-1 && br2==0;j++)
                {
                    if((v[i]==u[j]) && (str.Substring(i, 1) != str.Substring(j, 1)))
                    {
                        br2 = 1;
                        x = u[i];
                        for(k=0;k<n-1&&br3==0;k++)
                        {
                            if((v[j]==u[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                            {
                                br3 = 1;
                                y = v[k];
                            }
                            else
                            {
                                if((v[j]==v[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                                {
                                    br3 = 1;
                                    y = u[k];
                                }
                            }
                        }
                    }
                    else
                    {
                        if ((v[i] == v[j]) && (str.Substring(i, 1) != str.Substring(j, 1)))
                        {
                            br2 = 1;
                            x = u[i];
                            for (k = 0; k < n - 1 && br3 == 0; k++)
                            {
                                if ((u[j] == u[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                                {
                                    br3 = 1;
                                    y = v[k];
                                }
                                else
                                {
                                    if ((u[j] == v[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                                    {
                                        br3 = 1;
                                        y = u[k];
                                    }
                                }
                            }
                        }
                        else
                        {
                            if ((u[i] == u[j]) && (str.Substring(i, 1) != str.Substring(j, 1)))
                            {
                                br2 = 1;
                                x = v[i];
                                for (k = 0; k < n - 1 && br3 == 0; k++)
                                {
                                    if ((v[j] == u[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                                    {
                                        br3 = 1;
                                        y = v[k];
                                    }
                                    else
                                    {
                                        if ((v[j] == v[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                                        {
                                            br3 = 1;
                                            y = u[k];
                                        }
                                    }
                                }
                            }
                            else
                            {
                                if ((u[i] == v[j]) && (str.Substring(i, 1) != str.Substring(j, 1)))
                                {
                                    br2 = 1;
                                    x = v[i];
                                    for (k = 0; k < n - 1 && br3 == 0; k++)
                                    {
                                        if ((u[j] == u[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                                        {
                                            br3 = 1;
                                            y = v[k];
                                        }
                                        else
                                        {
                                            if ((v[j] == v[k]) && (str.Substring(j, 1) != str.Substring(k, 1)))
                                            {
                                                br3 = 1;
                                                y = u[k];
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                if ((br1 == br2) && (br2 == br3)&&(x<y))
                    br++;
                br2 = 0;
                br3 = 0;
            }
            Console.WriteLine(br);
            Console.ReadLine();
        }
    }
}