// Arup Guha
// 10/22/2026
// Solution to Kattis Problem: Red Blue Tree
// Used to illustrate Kruskal's Algorithm for the Minimum Spanning Tree Problem.
// https://open.kattis.com/problems/redbluetree

import java.util.*;

public class redbluetree {
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int n = stdin.nextInt();
		int numE = stdin.nextInt();
		int numBlue = stdin.nextInt();
		
		// red = 1 for this graph.
		edge[] red = new edge[numE];
		
		// blue = 1 for this graph.
		edge[] blue = new edge[numE];
		
		// Read the edges.
		for (int i=0; i<numE; i++) {
			
			// Get edge.
			char color = stdin.next().charAt(0);
			int v1 = stdin.nextInt()-1;
			int v2 = stdin.nextInt()-1;
			
			// red = 1 in red graph, 0 in blue graph.
			if (color == 'R') {
				red[i] = new edge(v1, v2, 1);
				blue[i] = new edge(v1, v2, 0);
			}
			
			// Other way around here.
			else {
				blue[i] = new edge(v1, v2, 1);
				red[i] = new edge(v1, v2, 0);
			}
		}
			
		// Run MST on both graphs getting min and max blue edges.
		int redMST = kruskals.mst(red, n);
		int maxBlue = n - 1 - redMST;
		int minBlue = kruskals.mst(blue, n);
		
		// We can do it!
		if (minBlue <= numBlue && numBlue <= maxBlue)
			System.out.println(1);
		
		// Here we can't.
		else
			System.out.println(0);
	}
}

/*** Disjoint Set with Path Compression ***/
class dset {

	public int[] parent;
	public int n;

	public dset(int size) {
		parent = new int[size];
		for (int i=0; i<size; i++)
			parent[i] = i;
	}

	// Finds the root of v and then reattaches v directly to this root.
	// This is path compression.
	public int find(int v) {
		if (parent[v] == v) return v;
		return parent[v] = find(parent[v]);
	}

	// Unions the sets storing v1 and v2. Returns false if already together and true
	// if the operation was performed.
	public boolean union(int v1, int v2) {

		// Find roots.
		int p1 = find(v1);
		int p2 = find(v2);
		if (p1 == p2) return false;

		// If we get here we have to merge the trees.
		parent[p2] = p1;
		return true;
	}
}

/*** Usual edge class. ***/
class edge implements Comparable<edge> {

	public int v1;
	public int v2;
	public int w;

	public edge(int a, int b, int weight) {
		v1 = a;
		v2 = b;
		w = weight;
	}

	public int compareTo(edge other) {
		return this.w - other.w;
	}
}

class kruskals {

	// We just give Kruskal's a list of all edges.
	public static int mst(edge[] list, int n) {
		
		// This is the greedy part.
		Arrays.sort(list);

		dset trees = new dset(n);
		int numEdges = 0, res = 0;

		// Consider edges in order.
		for (int i=0; i<list.length; i++) {

			// Try to put together these two trees.
			boolean merged = trees.union(list[i].v1, list[i].v2);
			if (!merged) continue;

			// Bookkeepping.
			numEdges++;
			res += list[i].w;
			if (numEdges == n-1) break;
		}

		// -1 indicates no MST, so not connected.
		return numEdges == n-1 ? res : -1;
	}
}
