id
int64
0
190k
prompt
stringlengths
21
13.4M
docstring
stringlengths
1
12k
12,538
import torch from im2mesh.utils.libkdtree import KDTree import numpy as np The provided code snippet includes necessary dependencies for implementing the `compute_iou` function. Write a Python function `def compute_iou(occ1, occ2)` to solve the following problem: Computes the Intersection over Union (IoU) value for tw...
Computes the Intersection over Union (IoU) value for two sets of occupancy values. Args: occ1 (tensor): first set of occupancy values occ2 (tensor): second set of occupancy values
12,539
import torch from im2mesh.utils.libkdtree import KDTree import numpy as np def chamfer_distance_naive(points1, points2): ''' Naive implementation of the Chamfer distance. Args: points1 (numpy array): first point set points2 (numpy array): second point set ''' assert(points1.size() ==...
Returns the chamfer distance for the sets of points. Args: points1 (numpy array): first point set points2 (numpy array): second point set use_kdtree (bool): whether to use a kdtree give_id (bool): whether to return the IDs of nearest points
12,540
import torch from im2mesh.utils.libkdtree import KDTree import numpy as np The provided code snippet includes necessary dependencies for implementing the `normalize_imagenet` function. Write a Python function `def normalize_imagenet(x)` to solve the following problem: Normalize input images according to ImageNet stand...
Normalize input images according to ImageNet standards. Args: x (tensor): input images
12,541
import torch from im2mesh.utils.libkdtree import KDTree import numpy as np def b_inv(b_mat): ''' Performs batch matrix inversion. Arguments: b_mat: the batch of matrices that should be inverted ''' eye = b_mat.new_ones(b_mat.size(-1)).diag().expand_as(b_mat) b_inv, _ = torch.gesv(eye, b_mat)...
Inverts the transformation. Args: points (tensor): points tensor transform (tensor): transformation matrices
12,542
import torch from im2mesh.utils.libkdtree import KDTree import numpy as np def fix_Rt_camera(Rt, loc, scale): ''' Fixes Rt camera matrix. Args: Rt (tensor): Rt camera matrix loc (tensor): location scale (float): scale ''' # Rt is B x 3 x 4 # loc is B x 3 and scale is B ba...
Returns dictionary of camera arguments. Args: data (dict): data dictionary loc_field (str): name of location field scale_field (str): name of scale field device (device): pytorch device
12,543
import logging import numpy as np import trimesh from im2mesh.utils.libkdtree import KDTree from im2mesh.utils.libmesh import check_mesh_contains from im2mesh.common import compute_iou The provided code snippet includes necessary dependencies for implementing the `distance_p2p` function. Write a Python function `def d...
Computes minimal distances of each point in points_src to points_tgt. Args: points_src (numpy array): source points normals_src (numpy array): source normals points_tgt (numpy array): target points normals_tgt (numpy array): target normals
12,544
import logging import numpy as np import trimesh from im2mesh.utils.libkdtree import KDTree from im2mesh.utils.libmesh import check_mesh_contains from im2mesh.common import compute_iou The provided code snippet includes necessary dependencies for implementing the `distance_p2m` function. Write a Python function `def d...
Compute minimal distances of each point in points to mesh. Args: points (numpy array): points array mesh (trimesh): mesh
12,545
import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from torchvision.utils import save_image import im2mesh.common as common def visualize_voxels(voxels, out_file=None, show=False): r''' Visualizes voxel data. Args: voxels (tensor): voxel data out_file...
r''' Visualizes the data with regard to its type. Args: data (tensor): batch of data data_type (string): data type (img, voxels or pointcloud) out_file (string): output file
12,546
import numpy as np from matplotlib import pyplot as plt from mpl_toolkits.mplot3d import Axes3D from torchvision.utils import save_image import im2mesh.common as common The provided code snippet includes necessary dependencies for implementing the `visualise_projection` function. Write a Python function `def visualise...
r''' Visualizes the transformation and projection to image plane. The first points of the batch are transformed and projected to the respective image. After performing the relevant transformations, the visualization is saved in the provided output_file path. Arguments: points (tensor): batch of point cloud points world...
12,547
import numpy as np import trimesh from scipy import ndimage from skimage.measure import block_reduce from im2mesh.utils.libvoxelize.voxelize import voxelize_mesh_ from im2mesh.utils.libmesh import check_mesh_contains from im2mesh.common import make_3d_grid def voxelize_surface(mesh, resolution): vertices = mesh.ver...
null
12,548
import numpy as np import trimesh from scipy import ndimage from skimage.measure import block_reduce from im2mesh.utils.libvoxelize.voxelize import voxelize_mesh_ from im2mesh.utils.libmesh import check_mesh_contains from im2mesh.common import make_3d_grid def voxelize_surface(mesh, resolution): vertices = mesh.ver...
null
12,549
import numpy as np import trimesh from scipy import ndimage from skimage.measure import block_reduce from im2mesh.utils.libvoxelize.voxelize import voxelize_mesh_ from im2mesh.utils.libmesh import check_mesh_contains from im2mesh.common import make_3d_grid def check_voxel_occupied(occupancy_grid): occ = occupancy_g...
null
12,550
import numpy as np class Voxels(object): """ Holds a binvox model. data is either a three-dimensional numpy boolean array (dense representation) or a two-dimensional numpy float array (coordinate representation). dims, translate and scale are the model metadata. dims are the voxel dimensions, e.g. [...
Read binary binvox format as array. Returns the model with accompanying metadata. Voxels are stored in a three-dimensional numpy array, which is simple and direct, but may use a lot of memory for large models. (Storage requirements are 8*(d^3) bytes, where d is the dimensions of the binvox model. Numpy boolean arrays u...
12,551
import numpy as np class Voxels(object): """ Holds a binvox model. data is either a three-dimensional numpy boolean array (dense representation) or a two-dimensional numpy float array (coordinate representation). dims, translate and scale are the model metadata. dims are the voxel dimensions, e.g. [...
Read binary binvox format as coordinates. Returns binvox model with voxels in a "coordinate" representation, i.e. an 3 x N array where N is the number of nonzero voxels. Each column corresponds to a nonzero voxel and the 3 rows are the (x, z, y) coordinates of the voxel. (The odd ordering is due to the way binvox forma...
12,552
import numpy as np The provided code snippet includes necessary dependencies for implementing the `dense_to_sparse` function. Write a Python function `def dense_to_sparse(voxel_data, dtype=np.int)` to solve the following problem: From dense representation to sparse (coordinate) representation. No coordinate reordering...
From dense representation to sparse (coordinate) representation. No coordinate reordering.
12,553
import numpy as np from sklearn.neighbors import NearestNeighbors def best_fit_transform(A, B): ''' Calculates the least-squares best-fit transform that maps corresponding points A to B in m spatial dimensions Input: A: Nxm numpy array of corresponding points B: Nxm numpy array of correspond...
The Iterative Closest Point method: finds best-fit transform that maps points A on to points B Input: A: Nxm numpy array of source mD points B: Nxm numpy array of destination mD point init_pose: (m+1)x(m+1) homogeneous transformation max_iterations: exit algorithm after max_iterations tolerance: convergence criteria Ou...
12,554
from scipy.spatial import Delaunay from itertools import combinations import numpy as np from im2mesh.utils import voxels def upsample3d_nn(x): xshape = x.shape yshape = (2*xshape[0], 2*xshape[1], 2*xshape[2]) y = np.zeros(yshape, dtype=x.dtype) y[::2, ::2, ::2] = x y[::2, ::2, 1::2] = x y[::2...
null
12,555
from scipy.spatial import Delaunay from itertools import combinations import numpy as np from im2mesh.utils import voxels def get_tetrahedon_volume(points): vectors = points[..., :3, :] - points[..., 3:, :] volume = 1/6 * np.linalg.det(vectors) return volume def sample_tetraheda(tetraheda_points, size): ...
null
12,556
import numpy as np from .triangle_hash import TriangleHash as _TriangleHash class MeshIntersector: def __init__(self, mesh, resolution=512): triangles = mesh.vertices[mesh.faces].astype(np.float64) n_tri = triangles.shape[0] self.resolution = resolution self.bbox_min = triangles.resh...
null
12,557
import os from plyfile import PlyElement, PlyData import numpy as np def load_pointcloud(in_file): plydata = PlyData.read(in_file) vertices = np.stack([ plydata['vertex']['x'], plydata['vertex']['y'], plydata['vertex']['z'] ], axis=1) return vertices
null
12,558
import os from plyfile import PlyElement, PlyData import numpy as np The provided code snippet includes necessary dependencies for implementing the `read_off` function. Write a Python function `def read_off(file)` to solve the following problem: Reads vertices and faces from an off file. :param file: path to file to r...
Reads vertices and faces from an off file. :param file: path to file to read :type file: str :return: vertices and faces as lists of tuples :rtype: [(float)], [(int)]
12,562
import argparse import numpy as np F_MM = 35. SENSOR_SIZE_MM = 32. PIXEL_ASPECT_RATIO = 1. RESOLUTION_PCT = 100 SKEW = 0. CAM_MAX_DIST = 1.75 IMG_W = 127 + 10 IMG_H = 127 + 10 CAM_ROT = np.matrix(((1.910685676922942e-15, 4.371138828673793e-08, 1.0), (1.0, -4.371138828673793e-08, -0.0), ...
Calculate 4x3 3D to 2D projection matrix given viewpoint parameters.
12,563
import argparse import trimesh import numpy as np import os import glob import sys from multiprocessing import Pool from functools import partial from im2mesh.utils import binvox_rw, voxels from im2mesh.utils.libmesh import check_mesh_contains def export_pointcloud(mesh, modelname, loc, scale, args): filename = os....
null
12,564
import sys import datetime from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMessageBox, qApp from PyQt5.QtGui import QIcon from PyQt5.QtCore import ( QtInfoMsg, QtWarningMsg, QtCriticalMsg, QtFatalMsg ) def qt_message_handler(mode, context, message): if mode == QtInfoMsg: mode = 'IN...
null
12,565
from collections import defaultdict import sys def input(): return sys.stdin.readline().rstrip()
null
12,566
import sys def input(): return sys.stdin.readline().rstrip()
null
12,568
import sys import re def input(): return sys.stdin.readline().rstrip()
null
12,572
import sys def palin(start, end, del_cnt): if del_cnt == 2: return del_cnt while start <= end: if string[start] != string[end]: a = palin(start + 1, end, del_cnt + 1) b = palin(start, end - 1, del_cnt + 1) return a if a <= b else b start += 1 ...
null
12,582
import sys start = list(map(int, input().split(':'))) end = list(map(int, input().split(':'))) def isBig(): if start[0] < end[0]: return 1 elif start[0] == end[0]: if start[1] < end[1]: return 1 elif start[1] == end[1]: if start[2] < end[2]: retur...
null
12,584
import sys def GCD(x,y): if y == 0: return x else: return GCD(y, x%y)
null
12,590
import sys return max(range(len(a)), key=lambda x: a[x] def argmax(a): return max(range(len(a)), key=lambda x: a[x])
null
12,593
from collections import deque import sys def input(): return sys.stdin.readline().rstrip()
null
12,594
from collections import deque import sys board = [[0]*N for _ in range(N)] visit = [[[False]*N for _ in range(N)] for _ in range(2)] def bfs(molds, t): def solution(cleans, molds): global board, visit molds = deque(molds) for _t in range(t): molds = bfs(molds, _t) for clean in cleans: y...
null
12,596
import sys def change(num, first = False): ret = '' while num: ret += chr(num % 2 + 48) num //= 2 while len(ret) < 3: ret += '0' idx = 3 if first: while idx > 1 and ret[idx - 1] == '0': idx -= 1 return ret[:idx][::-1]
null
12,598
import sys r_num = len(arr) c_num = len(arr[0]) temp = [arr[-(row + 1)] for row in range(r_num)] return tem temp = [arr[row][::-1] for row in range(arr_N)] return tem temp = [[arr[-(col + 1)][row] for col in range(arr_N)] for row in range(arr_M)] return temp temp = [[arr[col][-(row +...
null
12,599
import sys temp = [arr[-(row + 1)] for row in range(r_num)] return tem arr_M = len(arr[0]) temp = [arr[row][::-1] for row in range(arr_N)] return tem arr_M = len(arr[0]) temp = [[arr[-(col + 1)][row] for col in range(arr_N)] for row in range(arr_M)] return temp arr_N = len(arr) a...
null
12,600
import sys temp = [arr[-(row + 1)] for row in range(r_num)] return tem arr_M = len(arr[0]) temp = [arr[row][::-1] for row in range(arr_N)] return tem arr_M = len(arr[0]) temp = [[arr[-(col + 1)][row] for col in range(arr_N)] for row in range(arr_M)] return temp arr_N = len(arr) a...
null
12,601
import sys temp = [arr[-(row + 1)] for row in range(r_num)] return tem arr_M = len(arr[0]) temp = [arr[row][::-1] for row in range(arr_N)] return tem arr_M = len(arr[0]) temp = [[arr[-(col + 1)][row] for col in range(arr_N)] for row in range(arr_M)] return temp arr_N = len(arr) a...
null
12,602
import sys r_num = len(arr) c_num = len(arr[0]) temp = [arr[-(row + 1)] for row in range(r_num)] return tem temp = [arr[row][::-1] for row in range(arr_N)] return tem temp = [[arr[-(col + 1)][row] for col in range(arr_N)] for row in range(arr_M)] return temp temp = [[arr[col][-(row +...
null
12,603
import sys r_num = len(arr) c_num = len(arr[0]) temp = [arr[-(row + 1)] for row in range(r_num)] return tem temp = [arr[row][::-1] for row in range(arr_N)] return tem temp = [[arr[-(col + 1)][row] for col in range(arr_N)] for row in range(arr_M)] return temp temp = [[arr[col][-(row +...
null
12,605
import sys from collections import deque def input(): return sys.stdin.readline().rstrip()
null
12,607
import sys N, M = map(int, input().split()) arr = [] nx = [-1, 0, 1, 0] ny = [0, -1, 0, 1] dp = [[-1 for i in range(M)] for j in range(N)] for i in range(N): arr.append(list(map(int, input().split()))) def DFS(x,y): if x == N-1 and y == M-1: return 1 if dp[x][y] == -1: dp[x][y] = 0 ...
null
12,612
import sys import heapq def input(): return sys.stdin.readline().rstrip()
null
12,615
import sys tree = [[] for _ in range(n)] for nei in tree[v]: # Leaf까지 내려감 dp(nei) # 각 child를 root로 하는 subtree에 정보 전달하는데 걸리는 시간 모음 child_t.append(time[nei]) if not tree[v]: # Child가 없으면 0 child_t.append(0) child_t.sort(reverse=True) or i in range(len(child_t...
null
12,616
import sys sys.setrecursionlimit(1000000000) def input(): return sys.stdin.readline().rstrip()
null
12,617
import sys tree = [[] for _ in range(n+1)] stat = list(map(int, input().split())) def dp(v): con = 0 for nei in tree[v]: dp(nei) # Node v를 사용하지 않는 경우 -> max(dp_mat[nei]) 선택 # nei가 멘토든 아니든 상관 없이 가장 큰 경우만 가져오면 됨 dp_mat[v][1] += max(dp_mat[nei][0], dp_mat[nei][1]) # Node ...
null
12,618
import sys sys.setrecursionlimit(1000000)(int, input().split()) def input(): return sys.stdin.readline().rstrip()
null
12,619
import sys tree = [[] for _ in range(n+1)] num_child = [0]*(n+1) def dfs(cur, parent): if len(tree[cur]) == 1 and parent != -1: # Leaf node라면 num_child[cur] = 1 return 1 n_sub = 0 # cur를 root로 하는 subtree의 node 개수 for child in tree[cur]: if child != parent: # 각 child를 root로 하는 subtr...
null
12,620
import sys from itertools import permutations def input(): return sys.stdin.readline().rstrip()
null
12,621
import sys from itertools import combinations def input(): return sys.stdin.readline().rstrip()
null
12,622
import sys from itertools import combinations N = int(input()) pop = list(map(int, input().split())) pop.insert(0,0) arr = [[] for i in range(N+1)] for i in range(1, N+1): t = list(map(int, input().split())) arr[i] = t[1:] for i in range(1, N): comb_list = list(combinations(stan, i)) for comb in comb_li...
null
12,626
import sys from math import sqrt def input(): return sys.stdin.readline().rstrip()
null
12,627
import sys from math import sqrt sqrtN = int(sqrt(N)) def solve(N): ret = 4 for a in range(1, sqrtN + 1): if a * a == N: ret = 1 if ret == 1: break for b in range(1, sqrtN + 1): if a * a + b * b > N: break if a * ...
null
12,630
from collections import deque import sys for i in range(a): li = list(map(int, input().split())) for j in range(b): if li[j] == 1: sticker[c][1].append((i, j)) def rotate(arr, N): result = [] i_array = [] j_array = [] for item in arr: i,j = item ...
null
12,631
from collections import deque import sys for i in range(a): li = list(map(int, input().split())) for j in range(b): if li[j] == 1: sticker[c][1].append((i, j)) def check(n,m,arr,visit): for i in range(n): for j in range(m): chk = True ...
null
12,634
from itertools import combinations from collections import deque import sys def input(): return sys.stdin.readline().rstrip()
null
12,635
from itertools import combinations from collections import deque import sys def bfs(start1, start2, graph, N): result = [99999999 for _ in range(N+1)] result[0] = 0 # 인덱스 0은 더미 result[start1] = 0 result[start2] = 0 q = deque() q.append((start1, 0)) q.append((start2, 0)) visit = set() ...
null
12,636
from itertools import permutations import sys def input(): return sys.stdin.readline().rstrip()
null
12,637
from itertools import permutations import sys def shuffle(card1, card2, card3): card = card2 + card1 + card3 if len(card2) > 1: return shuffle(card2[:len(card2)//2] + card1, card2[len(card2)//2:], card3) else: card = card2 + card1 + card3 return card
null
12,641
import sys def isDifferentAndNotZero(num): if num[0] == num[1] or num[0] == num[2] or num[1] == num[2]: return False if '0' in num: return False return True
null
12,642
import sys N = int(input()) arr = [] for i in range(N): num, strike, ball = input().split() arr.append([num, int(strike), int(ball)]) for i in range(123,988): if isDifferentAndNotZero(str(i)) and baseball(str(i)): ans += 1 def baseball(num): flag = 0 for i in range(N): strike, ball ...
null
12,643
import sys from itertools import combinations as combi def input(): return sys.stdin.readline().rstrip()
null
12,644
import sys from itertools import combinations as combi N, M = map(int,input().split())st(map(int,input().split())) for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < N and 0 <= ny < M: if check[nx][ny]: #4개블럭값이 이전 블럭값이면 안되니까 false 해주고 ch...
null
12,645
import sys from itertools import combinations as combi N, M = map(int,input().split())st(map(int,input().split())) global answer for i in range(4): nx = x + dx[i] ny = y + dy[i] if 0 <= nx < N and 0 <= ny < M: if check[nx][ny]: #4개블럭값이 이전 블럭값이면 안되니까 false 해주고 ...
null
12,647
import sys N, C = map(int, input().split()) K = list(map(int, input().split())) ans = 0 def backTracking(num): global ans if num > N: return ans = max(ans,num) for i in K: num = num * 10 + i backTracking(num) num = (num - i) // 10
null
12,649
import sys def isPalindrome(s): return s == s[::-1]
null
12,652
import sys arr = [] for i in range(9): arr.append(int(input())) arr.remove(first) arr.remove(second) arr.sort() for i in arr: print(i) def findIndex(ans): for i in range(9): for j in range(i+1,9): if arr[i] + arr[j] == ans: return (arr[i], arr[j])
null
12,655
from bisect import bisect_left import sys def input(): return sys.stdin.readline().rstrip()
null
12,657
import sys arr = [] K = 0 for i in range(N): arr.append(int(input())) def binary_search(): global K start, end = max(arr), sum(arr) while start <= end: mid = (start + end) // 2 have,ct = 0,0 for i in arr: if have < i: have = mid - i ct...
null
12,659
import sys arr = list(map(int, input().split())) M = int(input()) def binary_search(): start, end = 0, max(arr) while start <= end: mid = (start + end) // 2 total = 0 for i in arr: if mid < i: total += mid else: total += i ...
null
12,660
import sys from bisect import bisect_left, bisect_right def input(): return sys.stdin.readline().rstrip()
null
12,662
import sys def binary_search(t): start, end = 0, len(arr)-1 while start <= end: mid = (start + end) // 2 if arr[mid] == t: return 1 elif arr[mid] > t: end = mid - 1 else: start = mid + 1 return 0
null
12,664
import sys arr = [] ans = 0 for i in range(K): arr.append(int(input())) def binary_search(): global ans start, end = 1, max(arr) while start <= end: ct = 0 mid = (start + end) // 2 for i in arr: ct += i // mid if ct < N: end = mid - 1 els...
null
12,666
import sys arr = list(map(int, input().split())) ans = 0 def binary_search(): global ans start, end = 0, max(arr) while start <= end: mid = (start + end) // 2 total_length = 0 for i in arr: if i - mid >= 0: total_length += i - mid if total_lengt...
null
12,681
import heapq import sys def input(): return sys.stdin.readline().rstrip()
null
12,685
import sys n, f_kind, max_seq, coupon = map(int, input().split()) eat = [0 for _ in range(3000001)] def answer(line, max_seq, coupon): count = 0 for i in range(max_seq): food_number = line[i] if not eat[food_number]: count += 1 eat[food_number] += 1 max_count = count ...
null
12,691
import sys def origami(start, end): if start == end: return True mid = (start + end) // 2 sign = True for i in range(start,mid): if status[i] == status[end-i]: sign = False break if sign: return origami(start, mid - 1) and origami(mid + 1, end) el...
null
12,693
import sys def find_parent(x): if parent[x] != x: parent[x] = find_parent(parent[x]) return parent[x] parent = [i for i in range(N)] def union(x,y): x = find_parent(x) y = find_parent(y) if x < y: parent[y] = x else: parent[x] = y
null
12,695
import sys gates = list(range(G + 1)) def find_max(x): if gates[x] != x: gates[x] = find_max(gates[x]) return gates[x]
null
12,697
import sys dis_set = [-1]*(n+1) if dis_set[x] < 0: # 해당 disjoint set의 최상단 root를 찾음 return x def find(x): def union(x, y): x_root = find(x) y_root = find(y) if x_root != y_root: #두 node의 root가 다르다면 -> 합쳐야 함 dis_set[y_root] = x_root
null
12,699
import sys from copy import deepcopy from collections import deque def input(): return sys.stdin.readline().rstrip()
null
12,703
import sys from collections import deque N, L, R = map(int, input().split()) arr = [] nx = [-1, 0, 1, 0] ny = [0, -1, 0, 1] for i in range(N): arr.append(list(map(int, input().split()))) while True: flag = 0 visited = [[0 for i in range(N)] for j in range(N)] for i in range(N): for j in range(N)...
null
12,704
import sys from collections import deque from copy import deepcopy def input(): return sys.stdin.readline().rstrip()
null
12,708
import sys from math import sqrt def GCD(x,y): if y == 0: return x else: return GCD(y, x%y)
null
12,715
import sys from collections import defaultdict def input(): return sys.stdin.readline().rstrip()
null
12,722
import sys month_days = calculate_days_per_month() day, time = L.split('/') day = int(day) def calculate_days_per_month(): month_days = {1: 31, 2: 28, 3: 31, 4: 30, 5: 31, 6: 30, 7: 31, 8: 31, 9: 30, 10: 31, 11: 30, 12: 31} days = [0] for month, day in month_days.items(): days.append(days[month-1] ...
null
12,723
import sys def change_str(_str): date, time, item, person = _str.split() _, month, day = map(int, date.split('-')) # 년도 필요없음 hour, minute = map(int, time.split(':')) return person, item, (month_days[month-1] + day) * 24 * 60 + hour * 60 + minute def solution(info, deadline_time, F): dic = {} pe...
null
12,724
import sys import heapq from collections import defaultdict def input(): return sys.stdin.readline().rstrip()
null
12,727
import sys def find_parent(x): if x != parent[x]: parent[x] = find_parent(parent[x]) return parent[x] parent = [i for i in range(N+1)] def union(x, y): x = find_parent(x) y = find_parent(y) if x < y: parent[y] = x else: parent[x] = y
null
12,728
import sys, math def input(): return sys.stdin.readline().rstrip()
null
12,729
import sys, math def find(parent, a): if parent[a] == a: return a parent[a] = find(parent, parent[a]) return parent[a] def union(parent, a, b): a = find(parent, a) b = find(parent, b) if a > b: parent[a] = b return True elif a < b: parent[b] = a retur...
null
12,731
import sys import heapq parents = list(range(N + 1)) def find_parent(x): if parents[x] != x: parents[x] = find_parent(parents[x]) return parents[x] def union_set(a, b): parent_a = find_parent(a) parent_b = find_parent(b) if parent_a < parent_b: parents[parent_b] = parent_a else:...
null
12,733
import sys def find_parent(x): parent = [i for i in range(N+1)] def union(x,y): x, y = find_parent(x), find_parent(y) if x < y: parent[y] = x else: parent[x] = y
null
12,735
import sys import heapq def find_parent(p): p_parents = [i for i in range(N)] def union_planet(p1, p2): p1_parent = find_parent(p1) p2_parent = find_parent(p2) if p1_parent == p2_parent: return False if p1_parent < p2_parent: p_parents[p2_parent] = p1_parent else: p_parents[...
null
12,737
import sys def find_parent(x): if x != parent[x]: parent[x] = find_parent(parent[x]) return parent[x] parent = [i for i in range(N+1)] if parent.count(parent[1]) == N: print(total - total_tree) else: print(-1) def union(x, y): x = find_parent(parent[x]) y = find_parent(parent[y]) i...
null
12,739
import sys while True: n, m = map(int, input().split()) if n == 0 and m == 0: break edge = [] total = 0 for _ in range(m): x, y, w = map(int, input().split()) edge.append([x, y, w]) total += w num_edge = 0 edge.sort(key=lambda x: -x[2]) # Disjoint set 구성 ...
null
12,748
import sys s = input() index = [ -1 for _ in range(N) ] current_index = 0 index[idx] = current_index current_index += 1 index[idx] = stack.pop() choose = choose[cnt] = 1 choose[cnt] = 0 def func(cnt): if cnt == current_index: erase_bracket_count = sum(choose) if era...
null
12,757
import sys stack = [] if stack: print(0) exit(0) def compress(): # Integer를 하나로 합쳐야 하니깐 길이가 2 이상이어야 함. while len(stack) > 1: # 두 개의 값이 무조건 Integer이어야 하므로 # Integer면 첫번째 원소가 None으로 되어 있음 a, integer1 = stack[-1] b, integer2 = stack[-2] if a or b: break ...
null
12,759
import sys N, M = map(int, input().split()) arr = sorted(list(map(int, input().split()))) choose = [ 0 for _ in range(10) ] def dfs(idx, cnt): global N, M if cnt == M: for idx in range(cnt): print(arr[choose[idx]], end=' ') print() return for i in range(idx,N): ...
null
12,761
import sys N, M = map(int, input().split()) choose = [ 0 for _ in range(10) ] used = [ 0 for _ in range(10) ] def dfs(idx, cnt): global N, M if cnt == M: for idx in range(cnt): print(choose[idx], end=' ') print() return for i in range(idx, N + 1): if used[i]: ...
null