



from collections import deque
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Optional[int]					)->Union[str, Any]:
      return input(__UpperCamelCase					).strip().split(''' '''					)
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						List[str]  ,					_SCREAMING_SNAKE_CASE :						List[str]					)->Tuple:
      _lowerCAmelCase			      =	{}
      for i in range(__UpperCamelCase					):
            _lowerCAmelCase			      =	[]

      for e in range(__UpperCamelCase					):
            _lowerCAmelCase      , _lowerCAmelCase			      =	(int(__UpperCamelCase					) for i in _input(f'''Edge {e + 1}: <node1> <node2> '''					))
            graph[x].append(__UpperCamelCase					)
      return graph
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						List[str]  ,					_SCREAMING_SNAKE_CASE :						str					)->Optional[int]:
      _lowerCAmelCase			      =	{}
      for i in range(__UpperCamelCase					):
            _lowerCAmelCase			      =	[]

      for e in range(__UpperCamelCase					):
            _lowerCAmelCase      , _lowerCAmelCase			      =	(int(__UpperCamelCase					) for i in _input(f'''Edge {e + 1}: <node1> <node2> '''					))
            graph[x].append(__UpperCamelCase					)
            graph[y].append(__UpperCamelCase					)
      return graph
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Tuple  ,					_SCREAMING_SNAKE_CASE :						Dict					)->List[Any]:
      _lowerCAmelCase			      =	{}
      for i in range(__UpperCamelCase					):
            _lowerCAmelCase			      =	[]

      for e in range(__UpperCamelCase					):
            _lowerCAmelCase      , _lowerCAmelCase      , _lowerCAmelCase			      =	(int(__UpperCamelCase					) for i in _input(f'''Edge {e + 1}: <node1> <node2> <weight> '''					))
            graph[x].append((y, w)					)
            graph[y].append((x, w)					)
      return graph


if __name__ == "__main__":
    UpperCAmelCase_      ,						UpperCAmelCase_          =				(int(i) for i in _input("Number of nodes and edges: "))

    UpperCAmelCase_          =				int(
        _input(
            "Press 1 or 2 or 3 \n"
            "1. Unweighted directed \n"
            "2. Unweighted undirected \n"
            "3. Weighted undirected \n"
        )[0]
    )

    UpperCAmelCase_          =				{
        1: initialize_unweighted_directed_graph,
        2: initialize_unweighted_undirected_graph,
        3: initialize_weighted_undirected_graph,
    }[graph_choice](n, m)
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Optional[int]  ,					_SCREAMING_SNAKE_CASE :						Union[str, Any]					)->int:
      _lowerCAmelCase      , _lowerCAmelCase			      =	{s}, [s]
      print(__UpperCamelCase					)
      while _s:
            _lowerCAmelCase			      =	0
            for i in g[_s[-1]]:
                  if i not in vis:
                        _s.append(__UpperCamelCase					)
                        vis.add(__UpperCamelCase					)
                        _lowerCAmelCase			      =	1
                        print(__UpperCamelCase					)
                        break
            if not flag:
                  _s.pop()
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Optional[Any]  ,					_SCREAMING_SNAKE_CASE :						Union[str, Any]					)->int:
      _lowerCAmelCase      , _lowerCAmelCase			      =	{s}, deque([s]					)
      print(__UpperCamelCase					)
      while q:
            _lowerCAmelCase			      =	q.popleft()
            for v in g[u]:
                  if v not in vis:
                        vis.add(__UpperCamelCase					)
                        q.append(__UpperCamelCase					)
                        print(__UpperCamelCase					)
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Tuple  ,					_SCREAMING_SNAKE_CASE :						Dict					)->List[str]:
      _lowerCAmelCase      , _lowerCAmelCase      , _lowerCAmelCase			      =	{s: 0}, set(), {s: 0}
      while True:
            if len(__UpperCamelCase					) == len(__UpperCamelCase					) - 1:
                  break
            _lowerCAmelCase			      =	1_0_0_0_0_0
            for i in dist:
                  if i not in known and dist[i] < mini:
                        _lowerCAmelCase			      =	dist[i]
                        _lowerCAmelCase			      =	i
            known.add(__UpperCamelCase					)
            for v in g[u]:
                  if v[0] not in known and dist[u] + v[1] < dist.get(v[0]  ,					1_0_0_0_0_0					):
                        _lowerCAmelCase			      =	dist[u] + v[1]
                        _lowerCAmelCase			      =	u
      for i in dist:
            if i != s:
                  print(dist[i]					)
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Optional[int]  ,					_SCREAMING_SNAKE_CASE :						str=None  ,					_SCREAMING_SNAKE_CASE :						str=None					)->Optional[Any]:







      if q is None:
            _lowerCAmelCase			      =	[1]
      if ind is None:
            _lowerCAmelCase			      =	[0] * (len(__UpperCamelCase					) + 1)  # SInce oth Index is ignored
            for u in g:
                  for v in g[u]:
                        ind[v] += 1
            _lowerCAmelCase			      =	deque()
            for i in g:
                  if ind[i] == 0:
                        q.append(__UpperCamelCase					)
      if len(__UpperCamelCase					) == 0:
            return
      _lowerCAmelCase			      =	q.popleft()
      print(__UpperCamelCase					)
      for w in g[v]:
            ind[w] -= 1
            if ind[w] == 0:
                  q.append(__UpperCamelCase					)
      topo(__UpperCamelCase  ,					__UpperCamelCase  ,					__UpperCamelCase					)
def 				UpperCAmelCase__		(					)->int:
      _lowerCAmelCase			      =	input().strip()
      _lowerCAmelCase			      =	[]
      for _ in range(__UpperCamelCase					):
            a.append(map(__UpperCamelCase  ,					input().strip().split()					)					)
      return a, n
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Union[str, Any]					)->Dict:
      ((_lowerCAmelCase)      , (_lowerCAmelCase))			      =	a_and_n
      _lowerCAmelCase			      =	list(__UpperCamelCase					)
      _lowerCAmelCase			      =	[[0] * n for i in range(__UpperCamelCase					)]
      for k in range(__UpperCamelCase					):
            for i in range(__UpperCamelCase					):
                  for j in range(__UpperCamelCase					):
                        if dist[i][j] > dist[i][k] + dist[k][j]:
                              _lowerCAmelCase			      =	dist[i][k] + dist[k][j]
                              _lowerCAmelCase			      =	k
      print(__UpperCamelCase					)
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						str  ,					_SCREAMING_SNAKE_CASE :						Any					)->Dict:
      _lowerCAmelCase      , _lowerCAmelCase      , _lowerCAmelCase			      =	{s: 0}, set(), {s: 0}
      while True:
            if len(__UpperCamelCase					) == len(__UpperCamelCase					) - 1:
                  break
            _lowerCAmelCase			      =	1_0_0_0_0_0
            for i in dist:
                  if i not in known and dist[i] < mini:
                        _lowerCAmelCase			      =	dist[i]
                        _lowerCAmelCase			      =	i
            known.add(__UpperCamelCase					)
            for v in g[u]:
                  if v[0] not in known and v[1] < dist.get(v[0]  ,					1_0_0_0_0_0					):
                        _lowerCAmelCase			      =	v[1]
                        _lowerCAmelCase			      =	u
      return dist
def 				UpperCAmelCase__		(					)->List[str]:
      _lowerCAmelCase      , _lowerCAmelCase			      =	map(__UpperCamelCase  ,					input().split(''' '''					)					)
      _lowerCAmelCase			      =	[]
      for _ in range(__UpperCamelCase					):
            edges.append(map(__UpperCamelCase  ,					input().split(''' '''					)					)					)
      return edges, n
def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						Tuple					)->Optional[Any]:
      ((_lowerCAmelCase)      , (_lowerCAmelCase))			      =	e_and_n
      e.sort(reverse=__UpperCamelCase  ,					key=lambda _SCREAMING_SNAKE_CASE					: x[2]					)
      _lowerCAmelCase			      =	[{i} for i in range(1  ,					n + 1					)]
      while True:
            if len(__UpperCamelCase					) == 1:
                  break
            print(__UpperCamelCase					)
            _lowerCAmelCase			      =	e.pop()
            for i in range(len(__UpperCamelCase					)					):
                  if x[0] in s[i]:
                        break
            for j in range(len(__UpperCamelCase					)					):
                  if x[1] in s[j]:
                        if i == j:
                              break
                        s[j].update(s[i]					)
                        s.pop(__UpperCamelCase					)
                        break


def 				UpperCAmelCase__		(					_SCREAMING_SNAKE_CASE :						int					)->Union[str, Any]:
      _lowerCAmelCase			      =	[]
      for node in graph:
            if not graph[node]:
                  isolated.append(__UpperCamelCase					)
      return isolated







"""simple docstring"""


import os
import unittest

from transformers import is_torch_available
from transformers.testing_utils import require_sentencepiece, require_tokenizers, require_torch, slow, torch_device


if is_torch_available():
       import torch

       from transformers import GPTaLMHeadModel


@require_torch
@require_sentencepiece
@require_tokenizers
class    snake_case						(				unittest.TestCase		):


   '''simple docstring'''

   @slow
   @unittest.skip('''Model is not available.'''    )
   def 							_SCREAMING_SNAKE_CASE							(      self					:	int    ):

     '''simple docstring'''
     __A		     =					'''nvidia/megatron-gpt2-345m/'''
     if "MYDIR" in os.environ:
       __A		     =					os.path.join(os.environ['''MYDIR'''],			_lowerCamelCase    )
     __A		     =					GPTaLMHeadModel.from_pretrained(_lowerCamelCase    )
     model.to(_lowerCamelCase    )
     model.half()

     __A		     =					torch.tensor(
         [[1_01, 71_10, 10_05, 10_56, 20_23, 1_13_33, 1_74_13, 10_29, 1_02]],			device=_lowerCamelCase,			dtype=torch.long,			)

     with torch.no_grad():
       __A		     =					model(_lowerCamelCase    ).logits

     __A		     =					torch.Size((1, 9, 5_02_57)    )
     self.assertEqual(output.shape,			_lowerCamelCase    )

     __A		     =					torch.tensor(
         [
             4.94_14,
             -0.29_20,
             -1.21_48,
             -4.02_73,
             -0.51_61,
             -5.21_09,
             -1.24_12,
             -1.83_01,
             -1.77_34,
             -4.71_48,
             -0.23_17,
             -1.08_11,
             -2.17_77,
             0.41_41,
             -3.79_69,
             -4.05_86,
             -2.53_32,
             -3.38_09,
             4.38_67,
         ],			device=_lowerCamelCase,			dtype=torch.half,			)

     for i in range(19    ):
       __A     ,       __A		     =					8 * i // 17, 27_92 * i  # along the diagonal
       __A     ,       __A		     =					output[0, r, c], expected_diag[i]
       __A		     =					f'row={r} col={c} computed={computed} expected={expected}'
       self.assertAlmostEqual(_lowerCamelCase,			_lowerCamelCase,			delta=1e-4,			msg=_lowerCamelCase    )




