<commit_before>#!/bin/python3

import math
import os
import random
import re
import sys
from collections import deque


class Node:

    def __init__(self, node_id, color_id, neighbors):
        self.node_id = node_id
        self.color_id = color_id
        self.neighbor_ids = neighbors
        self.marked_to_visit = False

    def add_neighbor(self, neighbor_id):
        self.neighbor_ids.append(neighbor_id)

    def __repr__(self):
        return "Node({}, {}, {})".format(self.node_id, self.color_id, self.neighbor_ids)

class Graph:

    def __init__(self, num_nodes, num_edges, edges, color_ids):
        self.num_nodes = num_nodes
        self.num_edges = num_edges
        self.edges = edges
        self.color_ids = color_ids

        self.nodes = []

        self.initialize_nodes()
        self.initialize_edges()

    def initialize_nodes(self):
        for i in range(self.num_nodes):
            self.nodes.append(Node(i, self.color_ids[i], []))

    def initialize_edges(self):
        for edge in self.edges:
            node_a, node_b = edge
            self.nodes[node_a - 1].add_neighbor(node_b - 1)
            self.nodes[node_b - 1].add_neighbor(node_a - 1)

    def smallest_path_length(self, color_to_find):
        self.mark_all_nodes_unvisited()
        to_visit = deque()
        initial_node = self.nodes[self.color_ids.index(color_to_find)]
        to_visit.append((initial_node, -1))
        initial_node.marked_to_visit = True

        while to_visit:
            current, depth = to_visit.popleft()
            if current != initial_node and current.color_id == color_to_find:
                return depth + 1
            else:
                for node_id in current.neighbor_ids:
                    neighbor = self.nodes[node_id]
                    if neighbor.marked_to_visit == False:
                        to_visit.append((neighbor, depth + 1))
                        neighbor.marked_to_visit = True

        return -1

    def mark_all_nodes_unvisited(self):
        for node in self.nodes:
            node.marked_to_visit = False

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    num_nodes, num_edges = map(int, input().split())
    edges = []

    for i in range(num_edges):
        edge = list(map(int, input().split()))
        edges.append(edge)

    color_ids = list(map(int, input().rstrip().split()))<commit_msg>Neighbors should be nodes not IDs<commit_after>#!/bin/python3

import math
import os
import random
import re
import sys
from collections import deque


class Node:

    def __init__(self, node_id, color_id, neighbors):
        self.node_id = node_id
        self.color_id = color_id
        self.neighbors = neighbors
        self.marked_to_visit = False

    def add_neighbor(self, neighbors):
        self.neighbors.append(neighbors)

    def __repr__(self):
        return "Node({}, {}, {})".format(self.node_id, self.color_id, self.neighbors)

class Graph:

    def __init__(self, num_nodes, num_edges, edges, color_ids):
        self.num_nodes = num_nodes
        self.num_edges = num_edges
        self.edges = edges
        self.color_ids = color_ids

        self.nodes = []

        self.initialize_nodes()
        self.initialize_edges()

    def initialize_nodes(self):
        for i in range(self.num_nodes):
            self.nodes.append(Node(i, self.color_ids[i], []))

    def initialize_edges(self):
        for edge_a, edge_b in self.edges:
            node_a = self.nodes[edge_a - 1]
            node_b = self.nodes[edge_b - 1]

            node_a.add_neighbor(node_b)
            node_b.add_neighbor(node_a)

    def smallest_path_length(self, color_to_find):
        self.mark_all_nodes_unvisited()
        to_visit = deque()
        initial_node = self.nodes[self.color_ids.index(color_to_find)]
        to_visit.append((initial_node, -1))
        initial_node.marked_to_visit = True

        while to_visit:
            current, depth = to_visit.popleft()
            if current != initial_node and current.color_id == color_to_find:
                return depth + 1
            else:
                for neighbor in current.neighbors:
                    if neighbor.marked_to_visit == False:
                        to_visit.append((neighbor, depth + 1))
                        neighbor.marked_to_visit = True

        return -1

    def mark_all_nodes_unvisited(self):
        for node in self.nodes:
            node.marked_to_visit = False

if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    num_nodes, num_edges = map(int, input().split())
    edges = []

    for i in range(num_edges):
        edge = list(map(int, input().split()))
        edges.append(edge)

    color_ids = list(map(int, input().rstrip().split()))
{'fraction_non_alphanumeric': 0.10370835952231301, 'fraction_numerical': 0.0033521893987010264, 'mean_word_length': 2.26986301369863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2954348', 'n_tokens_mistral': 1541, 'n_tokens_neox': 1474, 'n_words': 314}