





import unittest

from transformers import LiltConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...generation.test_utils import GenerationTesterMixin
from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
    import torch

    from transformers import (
        LiltForQuestionAnswering,
        LiltForSequenceClassification,
        LiltForTokenClassification,
        LiltModel,
    )
    from transformers.models.lilt.modeling_lilt import LILT_PRETRAINED_MODEL_ARCHIVE_LIST



class    _a     :






       """simple docstring"""

       def __init__(      self				:     Optional[int]							,	a				:     Optional[int]							,	a				:     List[Any]=13							,	a				:     Optional[int]=7							,	a				:     List[str]=True							,	a				:     int=True							,	a				:     List[Any]=True							,	a				:     Optional[int]=True							,	a				:     List[str]=99							,	a				:     Dict=24							,	a				:     List[str]=2							,	a				:     Optional[Any]=6							,	a				:     int=37							,	a				:     Optional[Any]="gelu"							,	a				:     Optional[Any]=0.1							,	a				:     List[Any]=0.1							,	a				:     Any=5_12							,	a				:     str=16							,	a				:     List[str]=2							,	a				:     Optional[int]=0.02							,	a				:     Tuple=3							,	a				:     Union[str, Any]=None							,	a				:     Any=10_00							,	)	->Tuple:
             SCREAMING_SNAKE_CASE__     :				str   =					parent
             SCREAMING_SNAKE_CASE__     :				Any   =					batch_size
             SCREAMING_SNAKE_CASE__     :				Any   =					seq_length
             SCREAMING_SNAKE_CASE__     :				Optional[int]   =					is_training
             SCREAMING_SNAKE_CASE__     :				List[Any]   =					use_input_mask
             SCREAMING_SNAKE_CASE__     :				int   =					use_token_type_ids
             SCREAMING_SNAKE_CASE__     :				Tuple   =					use_labels
             SCREAMING_SNAKE_CASE__     :				List[Any]   =					vocab_size
             SCREAMING_SNAKE_CASE__     :				int   =					hidden_size
             SCREAMING_SNAKE_CASE__     :				int   =					num_hidden_layers
             SCREAMING_SNAKE_CASE__     :				int   =					num_attention_heads
             SCREAMING_SNAKE_CASE__     :				List[Any]   =					intermediate_size
             SCREAMING_SNAKE_CASE__     :				Any   =					hidden_act
             SCREAMING_SNAKE_CASE__     :				str   =					hidden_dropout_prob
             SCREAMING_SNAKE_CASE__     :				Tuple   =					attention_probs_dropout_prob
             SCREAMING_SNAKE_CASE__     :				Dict   =					max_position_embeddings
             SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					type_vocab_size
             SCREAMING_SNAKE_CASE__     :				str   =					type_sequence_label_size
             SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					initializer_range
             SCREAMING_SNAKE_CASE__     :				List[str]   =					num_labels
             SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					scope
             SCREAMING_SNAKE_CASE__     :				Any   =					range_bbox

       def      A_  (      self				:     Tuple    )	->int:
             SCREAMING_SNAKE_CASE__     :				str   =					ids_tensor([self.batch_size, self.seq_length]							,	self.vocab_size    )

             SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					ids_tensor([self.batch_size, self.seq_length, 4]							,	self.range_bbox    )
             # Ensure that bbox is legal
             for i in range(bbox.shape[0]    ):
                   for j in range(bbox.shape[1]    ):
                         if bbox[i, j, 3] < bbox[i, j, 1]:
                               SCREAMING_SNAKE_CASE__     :				str   =					bbox[i, j, 3]
                               SCREAMING_SNAKE_CASE__     :				str   =					bbox[i, j, 1]
                               SCREAMING_SNAKE_CASE__     :				Dict   =					t
                         if bbox[i, j, 2] < bbox[i, j, 0]:
                               SCREAMING_SNAKE_CASE__     :				List[str]   =					bbox[i, j, 2]
                               SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					bbox[i, j, 0]
                               SCREAMING_SNAKE_CASE__     :				List[Any]   =					t

             SCREAMING_SNAKE_CASE__     :				Optional[int]   =					None
             if self.use_input_mask:
                   SCREAMING_SNAKE_CASE__     :				List[str]   =					ids_tensor([self.batch_size, self.seq_length]							,	vocab_size=2    )

             SCREAMING_SNAKE_CASE__     :				int   =					None
             if self.use_token_type_ids:
                   SCREAMING_SNAKE_CASE__     :				Any   =					ids_tensor([self.batch_size, self.seq_length]							,	self.type_vocab_size    )

             SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					None
             SCREAMING_SNAKE_CASE__     :				Any   =					None
             if self.use_labels:
                   SCREAMING_SNAKE_CASE__     :				List[Any]   =					ids_tensor([self.batch_size]							,	self.type_sequence_label_size    )
                   SCREAMING_SNAKE_CASE__     :				List[str]   =					ids_tensor([self.batch_size, self.seq_length]							,	self.num_labels    )

             SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.get_config()

             return config, input_ids, bbox, token_type_ids, input_mask, sequence_labels, token_labels

       def      A_  (      self				:     int    )	->Optional[int]:
             return LiltConfig(
                 vocab_size=self.vocab_size							,	hidden_size=self.hidden_size							,	num_hidden_layers=self.num_hidden_layers							,	num_attention_heads=self.num_attention_heads							,	intermediate_size=self.intermediate_size							,	hidden_act=self.hidden_act							,	hidden_dropout_prob=self.hidden_dropout_prob							,	attention_probs_dropout_prob=self.attention_probs_dropout_prob							,	max_position_embeddings=self.max_position_embeddings							,	type_vocab_size=self.type_vocab_size							,	initializer_range=self.initializer_range							,	)

       def      A_  (      self				:     Any							,	a				:     Union[str, Any]							,	a				:     Any							,	a				:     Dict							,	a				:     int							,	a				:     Union[str, Any]							,	a				:     Optional[Any]							,	a				:     Optional[int]							,	)	->str:
             SCREAMING_SNAKE_CASE__     :				Dict   =					LiltModel(config=UpperCAmelCase_    )
             model.to(UpperCAmelCase_    )
             model.eval()
             SCREAMING_SNAKE_CASE__     :				Dict   =					model(UpperCAmelCase_							,	bbox=UpperCAmelCase_							,	attention_mask=UpperCAmelCase_							,	token_type_ids=UpperCAmelCase_    )
             SCREAMING_SNAKE_CASE__     :				Any   =					model(UpperCAmelCase_							,	bbox=UpperCAmelCase_							,	token_type_ids=UpperCAmelCase_    )
             SCREAMING_SNAKE_CASE__     :				int   =					model(UpperCAmelCase_							,	bbox=UpperCAmelCase_    )

             self.parent.assertEqual(result.last_hidden_state.shape							,	(self.batch_size, self.seq_length, self.hidden_size)    )
             self.parent.assertEqual(result.pooler_output.shape							,	(self.batch_size, self.hidden_size)    )

       def      A_  (      self				:     int							,	a				:     str							,	a				:     Any							,	a				:     Tuple							,	a				:     Union[str, Any]							,	a				:     Optional[int]							,	a				:     str							,	a				:     List[Any]							,	)	->Dict:
             SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.num_labels
             SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					LiltForTokenClassification(config=UpperCAmelCase_    )
             model.to(UpperCAmelCase_    )
             model.eval()
             SCREAMING_SNAKE_CASE__     :				List[Any]   =					model(
                 UpperCAmelCase_							,	bbox=UpperCAmelCase_							,	attention_mask=UpperCAmelCase_							,	token_type_ids=UpperCAmelCase_							,	labels=UpperCAmelCase_    )
             self.parent.assertEqual(result.logits.shape							,	(self.batch_size, self.seq_length, self.num_labels)    )

       def      A_  (      self				:     Any							,	a				:     List[str]							,	a				:     Dict							,	a				:     str							,	a				:     List[str]							,	a				:     int							,	a				:     List[Any]							,	a				:     List[str]							,	)	->Dict:
             SCREAMING_SNAKE_CASE__     :				Tuple   =					LiltForQuestionAnswering(config=UpperCAmelCase_    )
             model.to(UpperCAmelCase_    )
             model.eval()
             SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					model(
                 UpperCAmelCase_							,	bbox=UpperCAmelCase_							,	attention_mask=UpperCAmelCase_							,	token_type_ids=UpperCAmelCase_							,	start_positions=UpperCAmelCase_							,	end_positions=UpperCAmelCase_							,	)
             self.parent.assertEqual(result.start_logits.shape							,	(self.batch_size, self.seq_length)    )
             self.parent.assertEqual(result.end_logits.shape							,	(self.batch_size, self.seq_length)    )






       def      A_  (      self				:     int    )	->Optional[int]:
             SCREAMING_SNAKE_CASE__     :				List[str]   =					self.prepare_config_and_inputs()
             (
                 (
                 SCREAMING_SNAKE_CASE__						
             ),							(
                 SCREAMING_SNAKE_CASE__						
             ),							(
                 SCREAMING_SNAKE_CASE__						
             ),							(
                 SCREAMING_SNAKE_CASE__						
             ),							(
                 SCREAMING_SNAKE_CASE__						
             ),							(
                 SCREAMING_SNAKE_CASE__						
             ),							(
                 SCREAMING_SNAKE_CASE__						
             ),													
             )     :				Union[str, Any]   =					config_and_inputs
             SCREAMING_SNAKE_CASE__     :				Any   =					{
                 "input_ids": input_ids,
                 "bbox": bbox,
                 "token_type_ids": token_type_ids,
                 "attention_mask": input_mask,
             }
             return config, inputs_dict







@require_torch
class    _a     (				snake_case__					,							snake_case__					,							snake_case__					,							unittest.TestCase							):






       """simple docstring"""

       snake_case_							 =						(
           (
               LiltModel,
               LiltForSequenceClassification,
               LiltForTokenClassification,
               LiltForQuestionAnswering,
           )
           if is_torch_available()
           else ()
       )
       snake_case_							 =						(
           {
               """feature-extraction""": LiltModel,
               """question-answering""": LiltForQuestionAnswering,
               """text-classification""": LiltForSequenceClassification,
               """token-classification""": LiltForTokenClassification,
               """zero-shot""": LiltForSequenceClassification,
           }
           if is_torch_available()
           else {}
       )
       snake_case_							 =						False
       snake_case_							 =						False

       def      A_  (      self				:     str							,	a				:     int							,	a				:     List[str]							,	a				:     Dict							,	a				:     int							,	a				:     Optional[int]    )	->Optional[int]:
             return True

       def      A_  (      self				:     Dict    )	->Union[str, Any]:
             SCREAMING_SNAKE_CASE__     :				List[Any]   =					LiltModelTester(self    )
             SCREAMING_SNAKE_CASE__     :				Optional[int]   =					ConfigTester(self							,	config_class=UpperCAmelCase_							,	hidden_size=37    )

       def      A_  (      self				:     str    )	->List[Any]:
             self.config_tester.run_common_tests()

       def      A_  (      self				:     List[str]    )	->int:
             SCREAMING_SNAKE_CASE__     :				int   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_model(*UpperCAmelCase_    )

       def      A_  (      self				:     Union[str, Any]    )	->List[str]:
             SCREAMING_SNAKE_CASE__     :				Tuple   =					self.model_tester.prepare_config_and_inputs()
             for type in ["absolute", "relative_key", "relative_key_query"]:
                   SCREAMING_SNAKE_CASE__     :				int   =					type
                   self.model_tester.create_and_check_model(*UpperCAmelCase_    )

       def      A_  (      self				:     List[Any]    )	->Dict:
             SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_token_classification(*UpperCAmelCase_    )

       def      A_  (      self				:     Optional[Any]    )	->Dict:
             SCREAMING_SNAKE_CASE__     :				Dict   =					self.model_tester.prepare_config_and_inputs()
             self.model_tester.create_and_check_for_question_answering(*UpperCAmelCase_    )






       @slow
       def      A_  (      self				:     Union[str, Any]    )	->Optional[int]:



             for model_name in LILT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                   SCREAMING_SNAKE_CASE__     :				Dict   =					LiltModel.from_pretrained(UpperCAmelCase_    )
                   self.assertIsNotNone(UpperCAmelCase_    )







@require_torch
@slow
class    _a     (				unittest.TestCase							):






       """simple docstring"""

       def      A_  (      self				:     Optional[int]    )	->Dict:
             SCREAMING_SNAKE_CASE__     :				List[Any]   =					LiltModel.from_pretrained("SCUT-DLVCLab/lilt-roberta-en-base"    ).to(UpperCAmelCase_    )

             SCREAMING_SNAKE_CASE__     :				Tuple   =					torch.tensor([[1, 2]]							,	device=UpperCAmelCase_    )
             SCREAMING_SNAKE_CASE__     :				Optional[int]   =					torch.tensor([[[1, 2, 3, 4], [5, 6, 7, 8]]]							,	device=UpperCAmelCase_    )

             # forward pass
             with torch.no_grad():
                   SCREAMING_SNAKE_CASE__     :				Optional[int]   =					model(input_ids=UpperCAmelCase_							,	bbox=UpperCAmelCase_    )

             SCREAMING_SNAKE_CASE__     :				str   =					torch.Size([1, 2, 7_68]    )
             SCREAMING_SNAKE_CASE__     :				Dict   =					torch.tensor(
                 [[-0.0653, 0.0950, -0.0061], [-0.0545, 0.0926, -0.0324]]							,	device=UpperCAmelCase_							,	)

             self.assertTrue(outputs.last_hidden_state.shape							,	UpperCAmelCase_    )
             self.assertTrue(torch.allclose(outputs.last_hidden_state[0, :, :3]							,	UpperCAmelCase_							,	atol=1E-3    )    )






import sys
from collections import defaultdict



class    _a     :






							"""simple docstring"""

							def __init__(      self				:     Any    )	->Dict:
													SCREAMING_SNAKE_CASE__     :				Tuple   =					[]

							def      A_  (      self				:     int							,	a				:     List[str]    )	->Dict:
													return self.node_position[vertex]

							def      A_  (      self				:     Optional[Any]							,	a				:     Any							,	a				:     List[str]    )	->Optional[Any]:
													SCREAMING_SNAKE_CASE__     :				str   =					pos

							def      A_  (      self				:     List[Any]							,	a				:     List[str]							,	a				:     Dict							,	a				:     Dict							,	a				:     List[Any]    )	->Optional[int]:
													if start > size // 2 - 1:
																			return
													else:
																			if 2 * start + 2 >= size:
																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					2 * start + 1
																			else:
																									if heap[2 * start + 1] < heap[2 * start + 2]:
																															SCREAMING_SNAKE_CASE__     :				Dict   =					2 * start + 1
																									else:
																															SCREAMING_SNAKE_CASE__     :				Tuple   =					2 * start + 2
																			if heap[smallest_child] < heap[start]:
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				int   =					heap[smallest_child], positions[smallest_child]
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Optional[int]   =					(
																									    heap[start],
																									    positions[start],
																									)
																									SCREAMING_SNAKE_CASE__,							SCREAMING_SNAKE_CASE__     :				Tuple   =					temp, tempa

																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					self.get_position(positions[smallest_child]    )
																									self.set_position(
																									    positions[smallest_child]							,	self.get_position(positions[start]    )    )
																									self.set_position(positions[start]							,	a    )

																									self.top_to_bottom(a							,	a							,	a							,	a    )

							def      A_  (      self				:     Union[str, Any]							,	a				:     Tuple							,	a				:     Tuple							,	a				:     Union[str, Any]							,	a				:     List[Any]    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__     :				List[Any]   =					position[index]

													while index != 0:
																			SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					int((index - 2) / 2    ) if index % 2 == 0 else int((index - 1) / 2    )

																			if val < heap[parent]:
																									SCREAMING_SNAKE_CASE__     :				List[Any]   =					heap[parent]
																									SCREAMING_SNAKE_CASE__     :				str   =					position[parent]
																									self.set_position(position[parent]							,	a    )
																			else:
																									SCREAMING_SNAKE_CASE__     :				int   =					val
																									SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					temp
																									self.set_position(a							,	a    )
																									break
																			SCREAMING_SNAKE_CASE__     :				Optional[int]   =					parent
													else:
																			SCREAMING_SNAKE_CASE__     :				int   =					val
																			SCREAMING_SNAKE_CASE__     :				List[str]   =					temp
																			self.set_position(a							,	0    )

							def      A_  (      self				:     Union[str, Any]							,	a				:     int							,	a				:     List[str]    )	->Union[str, Any]:
													SCREAMING_SNAKE_CASE__     :				List[str]   =					len(a    ) // 2 - 1
													for i in range(a							,	-1							,	-1    ):
																			self.top_to_bottom(a							,	a							,	len(a    )							,	a    )






							def      A_  (      self				:     Dict							,	a				:     List[Any]							,	a				:     Dict    )	->Optional[int]:
													SCREAMING_SNAKE_CASE__     :				Any   =					positions[0]
													SCREAMING_SNAKE_CASE__     :				Optional[int]   =					sys.maxsize
													self.top_to_bottom(a							,	0							,	len(a    )							,	a    )
													return temp







def       UpperCAmelCase							(     _lowerCamelCase      :  str     ):





						'''simple docstring'''


						SCREAMING_SNAKE_CASE__     :				Optional[int]   =					Heap()

						SCREAMING_SNAKE_CASE__     :				Any   =					[0] * len(_lowerCamelCase     )
						SCREAMING_SNAKE_CASE__     :				Any   =					[-1] * len(_lowerCamelCase     )  # Neighboring Tree Vertex of selected vertex
						# Minimum Distance of explored vertex with neighboring vertex of partial tree
						# formed in graph
						SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					[]  # Heap of Distance of vertices from their neighboring vertex
						SCREAMING_SNAKE_CASE__     :				str   =					[]

						for vertex in range(len(_lowerCamelCase     )     ):
												distance_tv.append(sys.maxsize     )
												positions.append(_lowerCamelCase     )
												heap.node_position.append(_lowerCamelCase     )

						SCREAMING_SNAKE_CASE__     :				List[Any]   =					[]
						SCREAMING_SNAKE_CASE__     :				int   =					1
						SCREAMING_SNAKE_CASE__     :				int   =					sys.maxsize
						for neighbor, distance in adjacency_list[0]:
												SCREAMING_SNAKE_CASE__     :				int   =					0
												SCREAMING_SNAKE_CASE__     :				List[str]   =					distance
						heap.heapify(_lowerCamelCase			,   _lowerCamelCase     )

						for _ in range(1			,   len(_lowerCamelCase     )     ):
												SCREAMING_SNAKE_CASE__     :				Optional[Any]   =					heap.delete_minimum(_lowerCamelCase			,   _lowerCamelCase     )
												if visited[vertex] == 0:
																		tree_edges.append((nbr_tv[vertex], vertex)     )
																		SCREAMING_SNAKE_CASE__     :				Union[str, Any]   =					1
																		for neighbor, distance in adjacency_list[vertex]:
																								if (
																								    visited[neighbor] == 0
																								    and distance < distance_tv[heap.get_position(_lowerCamelCase     )]
																								):
																														SCREAMING_SNAKE_CASE__     :				Any   =					distance
																														heap.bottom_to_top(
																														    _lowerCamelCase			,   heap.get_position(_lowerCamelCase     )			,   _lowerCamelCase			,   _lowerCamelCase     )
																														SCREAMING_SNAKE_CASE__     :				str   =					vertex
						return tree_edges


if __name__ == "__main__":  # pragma: no cover
				# < --------- Prims Algorithm --------- >
				__lowercase       :Union[str, Any]       =  int(input("Enter number of edges: ").strip())
				__lowercase       :Dict       =  defaultdict(list)
				for _ in range(edges_number):
								__lowercase       :Any       =  [int(x) for x in input().strip().split()]
								adjacency_list[edge[0]].append([edge[1], edge[2]])
								adjacency_list[edge[1]].append([edge[0], edge[2]])
				print(prisms_algorithm(adjacency_list))