


import argparse
import collections
import json
import os
import re
import string
import sys

import numpy as np


snake_case__    =						re.compile(r'''\b(a|an|the)\b''', re.UNICODE)

snake_case__    =						None


def 				lowerCamelCase__	(      )    ->	Any:





			"""simple docstring"""
			a__ :List[str]						  =    argparse.ArgumentParser("Official evaluation script for SQuAD version 2.0."				)
			parser.add_argument("data_file"	,  metavar="data.json"	,  help="Input data JSON file."				)
			parser.add_argument("pred_file"	,  metavar="pred.json"	,  help="Model predictions."				)
			parser.add_argument(
			    "--out-file"	,  "-o"	,  metavar="eval.json"	,  help="Write accuracy metrics to file (default is stdout)."				)
			parser.add_argument(
			    "--na-prob-file"	,  "-n"	,  metavar="na_prob.json"	,  help="Model estimates of probability of no answer."				)
			parser.add_argument(
			    "--na-prob-thresh"	,  "-t"	,  type=lowercase__	,  default=1.0	,  help="Predict \"\" if no-answer probability exceeds this (default = 1.0)."	,  )
			parser.add_argument(
			    "--out-image-dir"	,  "-p"	,  metavar="out_images"	,  default=lowercase__	,  help="Save precision-recall curves to directory."				)
			parser.add_argument("--verbose"	,  "-v"	,  action="store_true"				)
			if len(sys.argv				) == 1:
						parser.print_help()
						sys.exit(1				)
			return parser.parse_args()


def 				lowerCamelCase__	(      a	:   Any				)    ->	Any:





			"""simple docstring"""
			a__ :Optional[Any]						  =    {}
			for article in dataset:
						for p in article["paragraphs"]:
									for qa in p["qas"]:
												a__ :Dict						  =    bool(qa["answers"]["text"]				)
			return qid_to_has_ans


def 				lowerCamelCase__	(      a	:   List[str]				)    ->	str:





			"""simple docstring"""







			def remove_articles(a	:   str				):
						return ARTICLES_REGEX.sub(" "	,  lowercase__				)

			def white_space_fix(a	:   Optional[int]				):
						return " ".join(text.split()				)

			def remove_punc(a	:   Tuple				):
						a__ :int						  =    set(string.punctuation				)
						return "".join(ch for ch in text if ch not in exclude				)

			def lower(a	:   Union[str, Any]				):
						return text.lower()

			return white_space_fix(remove_articles(remove_punc(lower(lowercase__				)				)				)				)


def 				lowerCamelCase__	(      a	:   int				)    ->	str:





			"""simple docstring"""







			if not s:
						return []
			return normalize_answer(lowercase__				).split()


def 				lowerCamelCase__	(      a	:   Optional[int]	,  a	:   Dict				)    ->	Any:





			"""simple docstring"""
			return int(normalize_answer(lowercase__				) == normalize_answer(lowercase__				)				)


def 				lowerCamelCase__	(      a	:   List[Any]	,  a	:   Optional[Any]				)    ->	int:





			"""simple docstring"""
			a__ :Optional[Any]						  =    get_tokens(lowercase__				)
			a__ :Optional[int]						  =    get_tokens(lowercase__				)
			a__ :Any						  =    collections.Counter(lowercase__				) & collections.Counter(lowercase__				)
			a__ :Union[str, Any]						  =    sum(common.values()				)
			if len(lowercase__				) == 0 or len(lowercase__				) == 0:
						# If either is no-answer, then F1 is 1 if they agree, 0 otherwise
						return int(gold_toks == pred_toks				)
			if num_same == 0:
						return 0
			a__ :str						  =    1.0 * num_same / len(lowercase__				)
			a__ :List[str]						  =    1.0 * num_same / len(lowercase__				)
			a__ :Optional[Any]						  =    (2 * precision * recall) / (precision + recall)
			return fa


def 				lowerCamelCase__	(      a	:   int	,  a	:   Optional[int]				)    ->	Optional[Any]:





			"""simple docstring"""
			a__ :List[Any]						  =    {}
			a__ :Tuple						  =    {}
			for article in dataset:
						for p in article["paragraphs"]:
									for qa in p["qas"]:
												a__ :int						  =    qa["id"]
												a__ :Union[str, Any]						  =    [t for t in qa["answers"]["text"] if normalize_answer(lowercase__				)]
												if not gold_answers:
															# For unanswerable questions, only correct answer is empty string
															a__ :Any						  =    [""]
												if qid not in preds:
															print(F'''Missing prediction for {qid}'''				)
															continue
												a__ :Dict						  =    preds[qid]
												# Take max over all gold answers
												a__ :Union[str, Any]						  =    max(compute_exact(lowercase__	,  lowercase__				) for a in gold_answers				)
												a__ :Any						  =    max(compute_fa(lowercase__	,  lowercase__				) for a in gold_answers				)
			return exact_scores, fa_scores


def 				lowerCamelCase__	(      a	:   List[str]	,  a	:   Any	,  a	:   Optional[int]	,  a	:   Dict				)    ->	str:





			"""simple docstring"""
			a__ :List[Any]						  =    {}
			for qid, s in scores.items():
						a__ :Dict						  =    na_probs[qid] > na_prob_thresh
						if pred_na:
									a__ :List[Any]						  =    float(not qid_to_has_ans[qid]				)
						else:
									a__ :List[Any]						  =    s
			return new_scores


def 				lowerCamelCase__	(      a	:   str	,  a	:   Optional[int]	,  a	:   Optional[int]=None				)    ->	Tuple:





			"""simple docstring"""







			if not qid_list:
						a__ :Dict						  =    len(lowercase__				)
						return collections.OrderedDict(
						    [
						        ("exact", 1_0_0.0 * sum(exact_scores.values()				) / total),
						        ("f1", 1_0_0.0 * sum(fa_scores.values()				) / total),
						        ("total", total),
						    ]				)
			else:
						a__ :int						  =    len(lowercase__				)
						return collections.OrderedDict(
						    [
						        ("exact", 1_0_0.0 * sum(exact_scores[k] for k in qid_list				) / total),
						        ("f1", 1_0_0.0 * sum(fa_scores[k] for k in qid_list				) / total),
						        ("total", total),
						    ]				)


def 				lowerCamelCase__	(      a	:   List[Any]	,  a	:   List[str]	,  a	:   Tuple				)    ->	Tuple:





			"""simple docstring"""







			for k in new_eval:
						a__ :Optional[int]						  =    new_eval[k]


def 				lowerCamelCase__	(      a	:   int	,  a	:   List[str]	,  a	:   Optional[int]	,  a	:   int				)    ->	Dict:





			"""simple docstring"""
			plt.step(lowercase__	,  lowercase__	,  color="b"	,  alpha=0.2	,  where="post"				)
			plt.fill_between(lowercase__	,  lowercase__	,  step="post"	,  alpha=0.2	,  color="b"				)
			plt.xlabel("Recall"				)
			plt.ylabel("Precision"				)
			plt.xlim([0.0, 1.0_5]				)
			plt.ylim([0.0, 1.0_5]				)
			plt.title(lowercase__				)
			plt.savefig(lowercase__				)
			plt.clf()


def 				lowerCamelCase__	(      a	:   List[str]	,  a	:   Optional[Any]	,  a	:   Optional[int]	,  a	:   int	,  a	:   str=None	,  a	:   List[Any]=None				)    ->	str:





			"""simple docstring"""
			a__ :Any						  =    sorted(lowercase__	,  key=lambda a				: na_probs[k]				)
			a__ :List[str]						  =    0.0
			a__ :Union[str, Any]						  =    1.0
			a__ :str						  =    0.0
			a__ :Dict						  =    [1.0]
			a__ :str						  =    [0.0]
			a__ :Dict						  =    0.0
			for i, qid in enumerate(lowercase__				):
						if qid_to_has_ans[qid]:
									true_pos += scores[qid]
						a__ :int						  =    true_pos / float(i + 1				)
						a__ :Optional[Any]						  =    true_pos / float(lowercase__				)
						if i == len(lowercase__				) - 1 or na_probs[qid] != na_probs[qid_list[i + 1]]:
									# i.e., if we can put a threshold after this point
									avg_prec += cur_p * (cur_r - recalls[-1])
									precisions.append(lowercase__				)
									recalls.append(lowercase__				)
			if out_image:
						plot_pr_curve(lowercase__	,  lowercase__	,  lowercase__	,  lowercase__				)
			return {"ap": 1_0_0.0 * avg_prec}


def 				lowerCamelCase__	(      a	:   str	,  a	:   int	,  a	:   Optional[Any]	,  a	:   List[str]	,  a	:   Dict	,  a	:   str				)    ->	List[Any]:





			"""simple docstring"""







			if out_image_dir and not os.path.exists(lowercase__				):
						os.makedirs(lowercase__				)
			a__ :List[Any]						  =    sum(1 for v in qid_to_has_ans.values() if v				)
			if num_true_pos == 0:
						return
			a__ :List[str]						  =    make_precision_recall_eval(
			    lowercase__	,  lowercase__	,  lowercase__	,  lowercase__	,  out_image=os.path.join(lowercase__	,  "pr_exact.png"				)	,  title="Precision-Recall curve for Exact Match score"	,  )
			a__ :Optional[int]						  =    make_precision_recall_eval(
			    lowercase__	,  lowercase__	,  lowercase__	,  lowercase__	,  out_image=os.path.join(lowercase__	,  "pr_f1.png"				)	,  title="Precision-Recall curve for F1 score"	,  )
			a__ :Tuple						  =    {k: float(lowercase__				) for k, v in qid_to_has_ans.items()}
			a__ :Optional[int]						  =    make_precision_recall_eval(
			    lowercase__	,  lowercase__	,  lowercase__	,  lowercase__	,  out_image=os.path.join(lowercase__	,  "pr_oracle.png"				)	,  title="Oracle Precision-Recall curve (binary task of HasAns vs. NoAns)"	,  )
			merge_eval(lowercase__	,  lowercase__	,  "pr_exact"				)
			merge_eval(lowercase__	,  lowercase__	,  "pr_f1"				)
			merge_eval(lowercase__	,  lowercase__	,  "pr_oracle"				)


def 				lowerCamelCase__	(      a	:   Optional[int]	,  a	:   Tuple	,  a	:   Union[str, Any]	,  a	:   Any				)    ->	Optional[int]:





			"""simple docstring"""







			if not qid_list:
						return
			a__ :Dict						  =    [na_probs[k] for k in qid_list]
			a__ :str						  =    np.ones_like(lowercase__				) / float(len(lowercase__				)				)
			plt.hist(lowercase__	,  weights=lowercase__	,  bins=20	,  range=(0.0, 1.0)				)
			plt.xlabel("Model probability of no-answer"				)
			plt.ylabel("Proportion of dataset"				)
			plt.title(F'''Histogram of no-answer probability: {name}'''				)
			plt.savefig(os.path.join(lowercase__	,  F'''na_prob_hist_{name}.png'''				)				)
			plt.clf()


def 				lowerCamelCase__	(      a	:   List[Any]	,  a	:   Optional[int]	,  a	:   str	,  a	:   str				)    ->	List[Any]:





			"""simple docstring"""
			a__ :Tuple						  =    sum(1 for k in qid_to_has_ans if not qid_to_has_ans[k]				)
			a__ :Dict						  =    num_no_ans
			a__ :Tuple						  =    cur_score
			a__ :List[Any]						  =    0.0
			a__ :Union[str, Any]						  =    sorted(lowercase__	,  key=lambda a				: na_probs[k]				)
			for i, qid in enumerate(lowercase__				):
						if qid not in scores:
									continue
						if qid_to_has_ans[qid]:
									a__ :str						  =    scores[qid]
						else:
									if preds[qid]:
												a__ :str						  =    -1
									else:
												a__ :List[str]						  =    0
						cur_score += diff
						if cur_score > best_score:
									a__ :Optional[Any]						  =    cur_score
									a__ :List[Any]						  =    na_probs[qid]
			return 1_0_0.0 * best_score / len(lowercase__				), best_thresh


def 				lowerCamelCase__	(      a	:   Tuple	,  a	:   str	,  a	:   Union[str, Any]	,  a	:   Any	,  a	:   int	,  a	:   int				)    ->	Any:





			"""simple docstring"""
			a__  ,  a__ :int						  =    find_best_thresh(lowercase__	,  lowercase__	,  lowercase__	,  lowercase__				)
			a__  ,  a__ :Any						  =    find_best_thresh(lowercase__	,  lowercase__	,  lowercase__	,  lowercase__				)
			a__ :Tuple						  =    best_exact
			a__ :List[Any]						  =    exact_thresh
			a__ :List[Any]						  =    best_fa
			a__ :List[Any]						  =    fa_thresh


def 				lowerCamelCase__	(      )    ->	int:





			"""simple docstring"""







			with open(OPTS.data_file				) as f:
						a__ :str						  =    json.load(lowercase__				)
						a__ :Dict						  =    dataset_json["data"]
			with open(OPTS.pred_file				) as f:
						a__ :Optional[int]						  =    json.load(lowercase__				)
			if OPTS.na_prob_file:
						with open(OPTS.na_prob_file				) as f:
									a__ :Dict						  =    json.load(lowercase__				)
			else:
						a__ :int						  =    {k: 0.0 for k in preds}
			a__ :Optional[int]						  =    make_qid_to_has_ans(lowercase__				)  # maps qid to True/False
			a__ :Union[str, Any]						  =    [k for k, v in qid_to_has_ans.items() if v]
			a__ :str						  =    [k for k, v in qid_to_has_ans.items() if not v]
			a__  ,  a__ :Union[str, Any]						  =    get_raw_scores(lowercase__	,  lowercase__				)
			a__ :Union[str, Any]						  =    apply_no_ans_threshold(lowercase__	,  lowercase__	,  lowercase__	,  OPTS.na_prob_thresh				)
			a__ :Tuple						  =    apply_no_ans_threshold(lowercase__	,  lowercase__	,  lowercase__	,  OPTS.na_prob_thresh				)
			a__ :List[str]						  =    make_eval_dict(lowercase__	,  lowercase__				)
			if has_ans_qids:
						a__ :Union[str, Any]						  =    make_eval_dict(lowercase__	,  lowercase__	,  qid_list=lowercase__				)
						merge_eval(lowercase__	,  lowercase__	,  "HasAns"				)
			if no_ans_qids:
						a__ :List[Any]						  =    make_eval_dict(lowercase__	,  lowercase__	,  qid_list=lowercase__				)
						merge_eval(lowercase__	,  lowercase__	,  "NoAns"				)
			if OPTS.na_prob_file:
						find_all_best_thresh(lowercase__	,  lowercase__	,  lowercase__	,  lowercase__	,  lowercase__	,  lowercase__				)
			if OPTS.na_prob_file and OPTS.out_image_dir:
						run_precision_recall_analysis(lowercase__	,  lowercase__	,  lowercase__	,  lowercase__	,  lowercase__	,  OPTS.out_image_dir				)
						histogram_na_prob(lowercase__	,  lowercase__	,  OPTS.out_image_dir	,  "hasAns"				)
						histogram_na_prob(lowercase__	,  lowercase__	,  OPTS.out_image_dir	,  "noAns"				)
			if OPTS.out_file:
						with open(OPTS.out_file	,  "w"				) as f:
									json.dump(lowercase__	,  lowercase__				)
			else:
						print(json.dumps(lowercase__	,  indent=2				)				)


if __name__ == "__main__":
		snake_case__    =						parse_args()
		if OPTS.out_image_dir:
				import matplotlib

				matplotlib.use('''Agg''')
				import matplotlib.pyplot as plt
		main()






import sys
from collections import defaultdict


class 					lowerCAmelCase_ :




						def __init__(	self						:   Optional[int]						)      ->Any:






									"""simple docstring"""






									a__ :Optional[Any]						  =    []




						def  _snake_case					(	self						:   Optional[Any]   ,     __A						:   List[Any]						)      ->List[str]:






									"""simple docstring"""






									return self.node_position[vertex]




						def  _snake_case					(	self						:   Optional[Any]   ,     __A						:   str   ,     __A						:   Any						)      ->Dict:






									"""simple docstring"""






									a__ :Dict						  =    pos




						def  _snake_case					(	self						:   str   ,     __A						:   Union[str, Any]   ,     __A						:   Union[str, Any]   ,     __A						:   Optional[Any]   ,     __A						:   Optional[int]						)      ->List[Any]:






									"""simple docstring"""






									if start > size // 2 - 1:
												return
									else:
												if 2 * start + 2 >= size:
															a__ :str						  =    2 * start + 1
												else:
															if heap[2 * start + 1] < heap[2 * start + 2]:
																		a__ :Optional[int]						  =    2 * start + 1
															else:
																		a__ :List[Any]						  =    2 * start + 2
												if heap[smallest_child] < heap[start]:
															a__  ,  a__ :Optional[Any]						  =    heap[smallest_child], positions[smallest_child]
															a__  ,  a__ :int						  =    (
															    heap[start],
															    positions[start],
															)
															a__  ,  a__ :List[Any]						  =    temp, tempa

															a__ :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  _snake_case					(	self						:   List[str]   ,     __A						:   Any   ,     __A						:   List[str]   ,     __A						:   Any   ,     __A						:   str						)      ->Optional[Any]:






									"""simple docstring"""






									a__ :Optional[Any]						  =    position[index]

									while index != 0:
												a__ :str						  =    int((index - 2) / 2						) if index % 2 == 0 else int((index - 1) / 2						)

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




						def  _snake_case					(	self						:   Tuple   ,     __A						:   int   ,     __A						:   int						)      ->Union[str, Any]:






									"""simple docstring"""






									a__ :Tuple						  =    len(__A						) // 2 - 1
									for i in range(__A   ,     -1   ,     -1						):
												self.top_to_bottom(__A   ,     __A   ,     len(__A						)   ,     __A						)






						def  _snake_case					(	self						:   List[Any]   ,     __A						:   List[Any]   ,     __A						:   int						)      ->Optional[Any]:






									"""simple docstring"""






									a__ :Any						  =    positions[0]
									a__ :str						  =    sys.maxsize
									self.top_to_bottom(__A   ,     0   ,     len(__A						)   ,     __A						)
									return temp






def 				lowerCamelCase__	(      a	:   Any				)    ->	Union[str, Any]:





			"""simple docstring"""
			a__ :Tuple						  =    Heap()

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

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

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

			for _ in range(1	,  len(a				)				):
						a__ :Dict						  =    heap.delete_minimum(a	,  a				)
						if visited[vertex] == 0:
									tree_edges.append((nbr_tv[vertex], vertex)				)
									a__ :Optional[int]						  =    1
									for neighbor, distance in adjacency_list[vertex]:
												if (
												    visited[neighbor] == 0
												    and distance < distance_tv[heap.get_position(a				)]
												):
															a__ :List[str]						  =    distance
															heap.bottom_to_top(
															    a	,  heap.get_position(a				)	,  a	,  a				)
															a__ :str						  =    vertex
			return tree_edges


if __name__ == "__main__":  # pragma: no cover
		# < --------- Prims Algorithm --------- >
		snake_case__			 =						int(input('''Enter number of edges: ''').strip())
		snake_case__			 =						defaultdict(list)
		for _ in range(edges_number):
				snake_case__			 =						[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))


