module Graphical
	require 'set'

	def reachable_from(s, max_depth = nil)
		reached = Set[s]
		queue = [s]
		depth = 0
		loop {
			break if max_depth && depth >= max_depth
			next_queue = []
			until queue.empty?
				u = queue.shift
				each_out_connection_of(u){|v, _|
					next if reached.include?(v)
					reached << v
					next_queue << v
				}
			end
			break if next_queue.empty?
			queue = next_queue
			depth += 1
		}
		return reached
	end

	def bfs(start, goal)
		reached = Set[start]
		queue = [start]
		loop {
			next_queue = []
			until queue.empty?
				u = queue.shift
				return true if u == goal
				each_out_connection_of(u){|v, _|
					next if reached.include?(v)
					reached << v
					next_queue << v
				}
			end
			return false if next_queue.empty?
			queue = next_queue
		}
	end
end

class SimpleGraph
	include Graphical

	def add_node(property = {})
		Node.new(property)
	end

	def connect(u, v, property = {})
		u.neighbours << v
		v.neighbours << u
	end
	
	def disconnect(u, v)
		u.neighbours.delete(v)
		v.neighbours.delete(u)
	end

	class Node
		def initialize(property)
			@property = property
			@neighbours = Set.new
		end

		attr_reader :property, :neighbours
	end

	def each_out_connection_of(u)
		u.neighbours.each{|v|
			yield(v, 1)
		}
	end

	alias :each_in_connection_of :each_out_connection_of
end

n, m = gets.split.map &:to_i
g = SimpleGraph.new
nodes = (0..n-1).map{|i| g.add_node({:name => i}) }

b = Math.sqrt(m).ceil 

def g.each_out_connection_of(u)
	i = u.property[:name]
	super(u){|v, _|
		j = v.property[:name]
		i, j = j, i if i > j
		yield(v, 1) unless $to_be_del[[i, j]]
	}
end


(1..m).each_slice(29*b){|a|
	$to_be_del = {}
	queries = a.map {	
		q, i, j = gets.split.map &:to_i
		$to_be_del[[i, j]] = 0 if q == 2
		[q, i, j]
	}

	c_g = SimpleGraph.new
	c_nodes = (1..n).map{ c_g.add_node }

	hash = {}
	(0..n-1).each{|i|
		next if hash[i]
		u = nodes[i]
		g.reachable_from(u).each{|v|
			j = v.property[:name]
			hash[j] = 0
			c_nodes[j] = c_nodes[i]
		}
	}

	$to_be_del.each_key{|i, j|
		c_g.connect(c_nodes[i], c_nodes[j])	
	}

	queries.each{|q, i, j|
		case q
		when 1
			g.connect(nodes[i], nodes[j])
			c_g.connect(c_nodes[i], c_nodes[j])
		when 2
			g.disconnect(nodes[i], nodes[j])
			c_g.disconnect(c_nodes[i], c_nodes[j])
		when 3
			puts c_g.bfs(c_nodes[i], c_nodes[j]) ? 'YES' : 'NO'
		end
	}
}