본문 바로가기

분류 전체보기93

Dijkstra struct Dijkstra { using elem = pair; const ll INF = 2e18; int vol; vector dup; vector adj; Dijkstra(int _vol) { vol = _vol + 1; dup.resize(vol, INF); adj.resize(vol); } void connect(int u, int v, ll w) { adj[u].push_back({w, v}); } void run(int base) { priority_queue que; que.push({0, base}); dup[base] = 0; while (!que.empty()) { auto [cw, id] = que.top(); que.pop(); if (dup[id] < cw) continue; .. 2020. 8. 6.
Tree #include using namespace std; typedef long long ll; const int MAX = 100001; int parent[MAX]; struct Tree { int root, size; vector child[MAX], edge[MAX]; Tree() { root = -1; size = 0; } Tree(int n) { root = -1; size = n; } void addEdge(int u, int v) { edge[u].push_back(v); edge[v].push_back(u); } void build(int id) { if (root == -1) root = id; for (int next : edge[id]) { if (!parent[next]) { pare.. 2020. 8. 6.
Codeforces Round #660 (Div. 2) AB from sys import stdin T=int(stdin.readline()) for _ in range(T): n=int(stdin.readline()) if n 2020. 8. 6.
Educational Codeforces Round 92 (Rated for Div. 2) A from sys import stdin from math import gcd def lcm(a, b): return a * b / gcd(a, b) T=int(stdin.readline()) for _ in range(T): l,r=map(int,stdin.readline().split()) if l==1: print(1,2) else: if lcm(l,int(l*(1.5))) 2020. 8. 6.
Codeforces Round #658 (Div. 2) AB from sys import stdin T=int(stdin.readline()) A=[] B=[] for _ in range(T): n,m=map(int,stdin.readline().split()) A=list(map(int,stdin.readline().split())) B=list(map(int,stdin.readline().split())) res=list(set(A) & set(B)) if len(res)==0: print("NO") else: print("YES") print(1,res[0]) A - Common Subsequence from sys import stdin T=int(stdin.readline()) for _ in range(T): cnt=0 N=int(stdin.readli.. 2020. 8. 6.
Codeforces Round #661 (Div. 3) ABC from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input())): n=int(input()) s=sorted(list(map(int,input().split()))) if len(s)==1: print("YES") else: flag=True for i in range(n): if s[i]-s[i-1]>1: flag=False if flag: print("YES") else: print("NO") A - Remove Smallest from sys import stdin def input(): return stdin.readline().rstrip() for _ in range(int(input(.. 2020. 8. 6.