description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in... | n = int(input())
L0 = [int(x) for x in input().split()]
L1 = [int(x) for x in input().split()]
if n == 1:
print(max(L0[0], L1[0]))
else:
dp = [[0, 0] for i in range(n)]
dp[0][0] = L0[0]
dp[0][1] = L1[0]
dp[1][0] = dp[0][1] + L0[1]
dp[1][1] = dp[0][0] + L1[1]
for i in range(1, n):
dp[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR... |
Finally, a basketball court has been opened in SIS, so Demid has decided to hold a basketball exercise session. $2 \cdot n$ students have come to Demid's exercise session, and he lined up them into two rows of the same size (there are exactly $n$ people in each row). Students are numbered from $1$ to $n$ in each row in... | n = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
dp = [[(0) for _ in range(3)] for _ in range(n + 1)]
for j in range(3):
dp[0][j] = 0
dp[1][0] = A[0]
dp[1][1] = B[0]
dp[1][2] = 0
for i in range(2, n + 1):
for j in range(3):
if j == 0:
dp[i][j] = A[... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER NUMBER VAR N... |
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | t = input()
s = input()
n = len(s)
h = [0] * (n + 1)
h[0] = 0
j = 0
fa = [0] * (n + 1)
for i in range(2, n + 1):
while j and s[i - 1] != s[j]:
j = fa[j]
if s[i - 1] == s[j]:
j += 1
fa[i] = j
l = list()
j = fa[n]
while j > 0:
l.append(j)
j = fa[j]
tmp = t
t = s
s = tmp
n = len(s)
dp =... | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR ... |
Berland has a long and glorious history. To increase awareness about it among younger citizens, King of Berland decided to compose an anthem.
Though there are lots and lots of victories in history of Berland, there is the one that stand out the most. King wants to mention it in the anthem as many times as possible.
H... | def prefix(st):
t = 0
p = [0] * (len(st) + 1)
o = [0] * (len(st) + 1)
for i in range(2, len(st)):
while t > 0 and st[i] != st[t + 1]:
t = p[t]
if st[i] == st[t + 1]:
t += 1
p[i] = t
while t > 0:
o[t] = 1
t = p[t]
return o
s = " " ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR V... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | def solve(s, s1):
mx = 0
l = [([0] * (n + 1)) for i in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, n - i + 2):
if s[i - 1] == s1[j - 1]:
l[i][j] = 1 + l[i - 1][j - 1]
else:
l[i][j] = max(l[i - 1][j], l[i][j - 1])
if i ... | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER BI... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | def lcs(s1, s2):
m, n = len(s1), len(s2)
prev, cur = [0] * (n + 1), [0] * (n + 1)
for i in range(1, m + 1):
for j in range(1, n + 1):
if s1[i - 1] == s2[j - 1]:
cur[j] = 1 + prev[j - 1]
elif cur[j - 1] > prev[j]:
cur[j] = cur[j - 1]
... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER V... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | def lps(s):
n = len(s)
a = [0] * n
for i in range(n - 1, -1, -1):
back_up = 0
for j in range(i, n):
if j == i:
a[j] = 1
elif s[i] == s[j]:
temp = a[j]
a[j] = back_up + 2
back_up = temp
else:
... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR VAR ASSIGN V... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | for t in range(int(input())):
def func(s: str):
dp = [([0] * len(s)) for _ in range(len(s))]
for k in range(len(s)):
for i in range(len(s) - k):
j = k + i
if i == j:
dp[i][j] = 1
elif s[i] == s[j]:
d... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR VAR VAR VAR ... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | t = int(input())
def solve(n, x):
a, b = x, "".join(reversed(list(x)))
dp = [([0] * (n + 1)) for i in range(n + 1)]
mx = 0
for i in range(1, n + 1):
for j in range(1, n - i + 2):
if a[i - 1] == b[j - 1]:
dp[i][j] = dp[i - 1][j - 1] + 1
else:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMB... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | def lcs(X, Y):
m = n = len(Y)
mx = 0
L = [([0] * (n + 1)) for i in range(m + 1)]
for i in range(1, m + 1):
for j in range(1, n - i + 2):
if i == 0 or j == 0:
L[i][j] = 0
elif X[i - 1] == Y[j - 1]:
L[i][j] = L[i - 1][j - 1] + 1
e... | FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER IF VAR BIN_OP VAR NU... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | def solve(s, n):
dp = [([0] * n) for _ in range(n)]
for i in range(n - 1, -1, -1):
dp[i][i] = 1
for j in range(i + 1, n):
if s[i] == s[j]:
dp[i][j] = dp[i + 1][j - 1] + 2
else:
dp[i][j] = max(dp[i + 1][j], dp[i][j - 1])
return dp[0][n -... | FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BI... |
Alice and Bob are playing a game using a string S of length N. They both have their individual strings which are initially empty.
Both players take alternate turns. Alice starts first.
In Alice's turn, she will:
Choose a prefix of S;
Remove the chosen prefix from S;
Append the prefix to the end of her string.
In B... | def solve(n, s):
s = "!" + s + "!"
dp = [([0] * (n + 2)) for i in range(n + 2)]
for i in range(1, n + 1):
for j in reversed(range(i + 1, n + 1)):
dp[i][j] = max(dp[i - 1][j], dp[i][j + 1])
if s[i] == s[j]:
dp[i][j] = max(dp[i][j], dp[i - 1][j + 1] + 1)
ans... | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP STRING VAR STRING ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VA... |
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Chef invented a new game named Quick Battle Royale. $N$ people play the game. One or more rounds are played until all players except one are eliminated. In each round:
Let there be $x$ non-eliminated players at the start of ... | import sys
import time
start_time = time.time()
try:
sys.stdin = open("input.txt", "r")
except:
pass
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n = int(input())
a = [
0,
0,
1,
500000005,
944444453,
616319451,
9519447,
2... | IMPORT IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NU... |
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
Chef invented a new game named Quick Battle Royale. $N$ people play the game. One or more rounds are played until all players except one are eliminated. In each round:
Let there be $x$ non-eliminated players at the start of ... | for T in range(int(input())):
N = int(input())
a = [
0,
0,
1,
500000005,
944444453,
616319451,
9519447,
209734212,
296383343,
628293695,
892973932,
356721615,
785855324,
361737272,
967345863,
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBE... |
You have 2 counters a and b, both initialised as 0. You also have a score initialised as 0.
At the start of every minute from minute 1 to minute N, you must increase either a or b by 1.
Additionally, there are M events. The i^{th} event happens at minute T_{i}+0.5 and has type C_{i} (C_{i} \in \{1, 2\}).
At each eve... | for _ in range(int(input())):
n, m = map(int, input().split())
t = list(map(int, input().split()))
c = list(map(int, input().split()))
d = [[-3, -3, -3, -3, -3] for i in range(n + 1)]
d[0][2] = 0
idx = 0
for i in range(1, n + 1):
d[i][0] = max(d[i][0], d[i - 1][1])
d[i][1] = ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR... |
You have 2 counters a and b, both initialised as 0. You also have a score initialised as 0.
At the start of every minute from minute 1 to minute N, you must increase either a or b by 1.
Additionally, there are M events. The i^{th} event happens at minute T_{i}+0.5 and has type C_{i} (C_{i} \in \{1, 2\}).
At each eve... | for _ in range(int(input())):
n, m = [int(i) for i in input().split()]
n = n + 1
t = [int(i) for i in input().split()]
c = [int(i) for i in input().split()]
C = {}
for i in range(m):
C[t[i] + 1] = c[i]
dp = [[(-1000000000.0) for i in range(5)] for j in range(n + 1)]
dp[0][2] = 0
... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VA... |
You have 2 counters a and b, both initialised as 0. You also have a score initialised as 0.
At the start of every minute from minute 1 to minute N, you must increase either a or b by 1.
Additionally, there are M events. The i^{th} event happens at minute T_{i}+0.5 and has type C_{i} (C_{i} \in \{1, 2\}).
At each eve... | inf = 10**9
for _ in range(int(input())):
n, m = map(int, input().split())
times = list(map(int, input().split()))
types = list(map(int, input().split()))
dp = [[-inf, -inf, -inf, -inf, -inf] for _ in range(n + 2)]
dp[0][2] = 0
ptr = 0
for i in range(1, n + 1):
for dif in range(5):
... | ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR VAR FUNC_CA... |
You have 2 counters a and b, both initialised as 0. You also have a score initialised as 0.
At the start of every minute from minute 1 to minute N, you must increase either a or b by 1.
Additionally, there are M events. The i^{th} event happens at minute T_{i}+0.5 and has type C_{i} (C_{i} \in \{1, 2\}).
At each eve... | TT = int(input())
for tt in range(TT):
n, m = map(int, input().split())
T = map(int, input().split())
C = map(int, input().split())
state = [0, -100, -100]
prev_t, prev_c = 0, 0
for t, c in zip(T, C):
diff = t - prev_t
new_state = [-100, -100, -100]
if c == prev_c:
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR ... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
p = len(str)
q = len(Query)
f = ord(str[0]) - 97
a = [[(0) for i in range(26)] for j in range(max(p, q))]
a[0][ord(str[0]) - 97] = 1
for i in range(1, max(p, q)):
a[i] = a[i - 1].copy()
if i <... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, _str, Query):
a = []
for _list in Query:
substring = _str[_list[0] - 1 : _list[1]]
a.append(len(set(substring)))
return a | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
res = []
for i in Query:
countdistinct = helper(str, i[0] - 1, i[1])
res.append(countdistinct)
return res
def helper(str, i, j):
dis = set()
for a in str[i:j]:
dis.add(a)
return len(dis) | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN FUNC_CALL VAR VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
l = []
for i in Query:
x = str[i[0] - 1 : i[1]]
l.append(x)
x = []
for i in l:
s = ""
for j in i:
if j not in s:
s += j
x.append(len(s))... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR STRING FOR VAR VAR IF VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
res = []
for i in Query:
cnt = 0
s1 = str[i[0] - 1 : i[1]]
p = set(s1)
res.append(len(p))
return res | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, Query):
l = [(0) for i in range(26)]
d = dict()
d[-1] = [(0) for i in range(26)]
l1 = []
for i in range(len(s)):
l[ord(s[i]) - ord("a")] += 1
d[i] = [i for i in l]
for i in Query:
a, b = i[0... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR VAR VAR VAR VAR FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR N... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, q):
s = list(s)
c = []
for i in q:
a, b = i[0], i[1]
c.append(len(set(s[a - 1 : b])))
return c | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
don = []
for query in Query:
l = query[0]
r = query[1]
arr = str[l - 1 : r]
don.append(len(set(arr)))
return don | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
lst = []
for i in Query:
myDict = {}
lst.append(self.fun(str, i[0] - 1, i[1] - 1, myDict))
return lst
def fun(self, str, l, r, myDict):
if l == r:
if str[l] not in myDict:
ret... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR DICT EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR RETURN VAR FUNC_DEF IF VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN BIN_OP NUMBER FUNC_CALL VAR VAR VAR BIN_OP V... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
lst = []
for i in Query:
L = i[0]
R = i[1]
lst1 = []
for i in range(L, R + 1):
if str[i - 1] not in lst1:
lst1.append(str[i - 1])
lst.append(len(lst1))
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, st, Query):
res = []
for q in Query:
start = q[0] - 1
end = q[1] - 1
s = st[start : end + 1]
new_set = set(s)
res.append(len(new_set))
return res | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, Query):
n = len(s)
dp = [[(0) for i in range(n)] for j in range(n)]
for i in range(n):
f = dict()
for j in range(i, n):
if s[j] not in f:
f[s[j]] = 1
dp[i][j] = len(f)
... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMB... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, S, Query):
N = len(S)
dp = [[(0) for i in range(26)] for i in range(N + 1)]
for i in range(N):
for j in range(26):
dp[i + 1][j] = dp[i][j]
dp[i + 1][ord(S[i]) - ord("a")] += 1
ans = []
for l, r in ... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIS... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
ans = []
for i in Query:
arr = []
count = 0
for j in range(i[0] - 1, i[1]):
if str[j] in arr:
pass
else:
arr.append(str[j])
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
unique_chars = [([0] * (len(str) + 1)) for _ in range(26)]
for english_ch_idx in range(26):
ch = chr(ord("a") + english_ch_idx)
prefix_sum = 0
for idx in range(1, len(str) + 1):
if str[idx - 1] ==... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VA... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, q):
s = "a" + s
maps = [{} for n in range(len(s))]
temp = {}
ans = []
for n in range(len(s)):
if s[n] not in temp:
temp[s[n]] = 0
temp[s[n]] += 1
maps[n] = temp.copy()
for n ... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP STRING VAR ASSIGN VAR DICT VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR DICT ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FOR VAR VAR ASSIGN LIST VAR VAR VAR ASSIGN VAR FUNC_CALL VA... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, a):
out = []
for i in a:
out.append(len(set(str[i[0] - 1 : i[1]])))
return out | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
res = []
for i in Query:
count = [0] * 26
c = 0
for j in range(i[0] - 1, i[1]):
if count[ord(str[j]) - ord("a")] == 0:
c += 1
count[ord(str[j]) - ord("a")] += 1... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER EXPR FUNC_CALL VAR VAR R... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, query):
ans = []
for i, j in query:
hashmap = {}
count = 0
for x in s[i - 1 : j]:
if hashmap.get(x) == None:
hashmap[x] = 1
count += 1
ans.append(count)
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR VAR ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR BIN_OP VAR NUMBER VAR IF FUNC_CALL VAR VAR NONE ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
r = []
for i in Query:
r.append(self.findunique(str[i[0] - 1 : i[1]]))
return r
def findunique(self, s):
d = dict()
for i in s:
d[i] = 0
return len(d) | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, queries):
length = []
for query in queries:
left, right = query
length.append(len(set(str[left - 1 : right])))
return length | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
l = []
w = []
for i in str:
l.append(i)
for i in Query:
k = []
g = []
for j in range(i[0] - 1, i[1]):
if l[j] not in k:
k.append(l[j])
w... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
S = str
ans = []
for i in range(0, len(Query)):
sets = set(S[Query[i][0] - 1 : Query[i][1]])
ans.append(len(sets))
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
res = []
l = len(str)
dp = [[(0) for c in range(l + 1)] for r in range(26)]
for r in range(26):
for c in range(1, l + 1):
if ord(str[c - 1]) - ord("a") == r:
dp[r][c] = dp[r][c - 1] + ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING VAR ASSIGN VAR VAR VAR BIN_OP VAR ... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
ans = []
for element in Query:
temp = str[element[0] - 1 : element[1]]
dicti = {}
count = 0
for i in temp:
if not i in dicti:
count += 1
dicti[i... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR DICT ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
res = []
for queryi in Query:
left, right = queryi[0], queryi[1]
tmp = set()
for i in range(left - 1, right):
tmp.add(str[i])
res.append(len(tmp))
return res | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
dp = [([0] * 26) for i in range(len(str) + 1)]
n = len(str)
ans = list()
for i in range(1, n + 1):
for j in range(26):
dp[i][j] = dp[i - 1][j]
dp[i][ord(str[i - 1]) - 97] = dp[i - 1][ord(str[i... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
d = []
ans = []
for i in range(len(str)):
p = []
d.append(p)
d1 = [0] * 26
for i in range(len(str)):
p = ord(str[i]) - 97
d1[p] += 1
h = d1.copy()
d[i] ... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FOR VAR... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, string, Query):
dp = [["" for i in range(len(string))] for j in range(len(string))]
for i in range(len(string)):
dp[i][i] = string[i]
for i in range(len(string) - 1):
for j in range(i + 1, len(string)):
dp[i][j] =... | CLASS_DEF FUNC_DEF ASSIGN VAR STRING VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR BIN_OP VAR VA... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, Q):
l1 = []
for i in Q:
j, k = i
x = set(list(s[j - 1 : k]))
l1.append(len(x))
return l1 | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, q):
p = []
l = [0] * 26
for i in range(len(s)):
l[ord(s[i]) - 97] += 1
p.append(l.copy())
ans = []
for i, j in q:
c = 0
for z in range(26):
if i == 1:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR NUMBER... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, Q):
n = len(s)
dp = [[(0) for i in range(26)] for k in range(n + 1)]
for i in range(1, n + 1):
for j in range(26):
dp[i][j] = dp[i - 1][j]
dp[i][ord(s[i - 1]) - ord("a")] += 1
k = []
for p in ra... | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR STRING ... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, string, Query):
lst = []
for q in Query:
l = q[0] - 1
r = q[1]
if l < 0:
l = 0
if r > len(string):
r = len(string)
s = set()
for char in string[l:r]:
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR RETURN VA... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
arr = [[(0) for i in range(26)] for j in range(len(str) + 1)]
for i in range(len(str)):
ind = ord(str[i]) - 97
arr[i + 1][ind] = 1
for j in range(26):
arr[i + 1][j] += arr[i][j]
ans = []
... | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR LIS... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, s, queries):
letters = [(ord(c) - 97) for c in s]
n = len(letters)
counts = []
counts.append([0] * 26)
for i in range(n):
c = letters[i]
current = counts[i][:]
current[c] += 1
counts.append... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR BIN_OP LIST NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN V... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
final = []
for i in Query:
chars = set()
start = i[0] - 1
end = i[1]
tot = len(set(str[start:end]))
final.append(tot)
return final | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def unique(self, str, n, b):
d = {}
p = [(0) for i in range(n)]
ind = b
for i in range(b, n):
try:
d[str[i]] += 1
except:
d[str[i]] = 1
p[ind] = len(d.keys())
ind += 1
return p
... | CLASS_DEF FUNC_DEF ASSIGN VAR DICT ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR VAR FUNC_CAL... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
out = []
a = [[(0) for i in range(26)] for j in range(len(str) + 1)]
for i in range(len(str)):
for k in range(len(a[i + 1])):
if k == ord(str[i]) - 97:
a[i + 1][k] = a[i][k] + 1
... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, strs, query):
ans = []
s = ""
for i in range(len(query)):
x = query[i][0]
y = query[i][1]
s = strs[x - 1 : y]
ans.append(len(set(s)))
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
tmp_list = []
for i in range(len(Query)):
tmp_list.append(len(set(str[Query[i][0] - 1 : Query[i][1]])))
return tmp_list | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
result = []
for L, R in Query:
d = {}
for i in range(L - 1, R):
if str[i] not in d:
d[str[i]] = 1
else:
d[str[i]] += 1
result.append(len(d))... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST FOR VAR VAR VAR ASSIGN VAR DICT FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str1, l):
l1 = []
s1 = ""
for i in range(len(l)):
for j in range(l[i][0] - 1, l[i][1]):
if str1[j] not in s1:
s1 += str1[j]
l1.append(len(s1))
s1 = ""
return l1 | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR STRING RETURN VAR |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
ans = [0] * len(Query)
d = set()
for i in range(len(Query)):
a = Query[i][0]
b = Query[i][1]
for j in range(a, b + 1):
d.add(str[j - 1])
ans[i] = len(d)
d = set()
... | CLASS_DEF FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CA... |
Given a string str you have to answer several queries on that string. In each query you will be provided two values L and R and you have to find the number of distinct characters in the sub string from index L to index R (inclusive) of the original string.
Example 1:
Input: str = "abcbaed",
Query = {{1,4},{2,4},{1,7}... | class Solution:
def SolveQueris(self, str, Query):
result = []
d = {}
for i in Query:
for j in str[i[0] - 1 : i[1]]:
if j not in d:
d[j] = 1
else:
d[j] += 1
result.append(len(d))
d.cl... | CLASS_DEF FUNC_DEF ASSIGN VAR LIST ASSIGN VAR DICT FOR VAR VAR FOR VAR VAR BIN_OP VAR NUMBER NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR RETURN VAR |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
def dfs(graph, ver):
used = set()
level = [ver]
depth = [0] * (len(graph) + 1)
levels_number = 0
while level:
new_level = []
for vertex in level:
used.add(vertex)
... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FOR VAR... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, a, b, da, db = map(int, input().split())
g = [[] for i in range(n)]
for i in range(n - 1):
u, v = map(int, input().split())
g[u - 1].append(v - 1)
g[v - 1].append(u - 1)
a -= 1
b -= 1
d0 = [0] *... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
sys.setrecursionlimit(10**5)
def search(tree, cur, find, was):
was.add(cur)
for i in tree[cur]:
if i == find:
return 1, True
elif not i in was:
a = search(tree, i, find, was)
if a[1]:
return a[0] + 1, a[1]
return -1, False
d... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR RETURN NUMBER NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER RETURN BIN_OP VAR NUMBER NUMBER VAR NUMBER RETURN NUMBER NUMBER FUNC_DEF EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VA... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | from sys import stdin
class Problem:
def __init__(self, n, a, b, da, db, e):
self.n = n
self.a = a - 1
self.b = b - 1
self.da = da
self.db = db
self.g = [[] for i in range(n)]
for u, v in e:
self.g[u - 1].append(v - 1)
self.g[v - 1].... | CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF NUMBER ASSIGN VAR VAR VAR... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
def input():
return sys.stdin.readline().strip()
def list2d(a, b, c):
return [([c] * b) for i in range(a)]
def list3d(a, b, c, d):
return [[([d] * c) for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e):
return [[[([e] * d) for j in range(c)] for j in range(b)] for i in ran... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF RETURN BIN_OP LIST VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_DEF NUMBER RETURN FUNC_CALL ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
def f():
n, a, b, da, db = map(int, input().split())
T = [[] for _ in range(n + 1)]
for _ in range(n - 1):
u, v = map(int, input().split())
T[u].append(v)
T[v].append(u)
dist = [-1] * (n + 1)
dist[a] = 0
m = 0
v = -1
stack ... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | for t in range(int(input())):
n, a, b, da, db = map(int, input().split())
graph = [set() for i in range(n + 1)]
for i in range(n - 1):
u, v = map(int, input().split())
graph[u].add(v)
graph[v].add(u)
visited = {1}
last_visits = set()
visit_now = {1}
while len(visited)... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL V... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | def dfs(x, p):
l = 0
for i in graph[x]:
if i != p:
depth[i] = depth[x] + 1
cur = 1 + dfs(i, x)
diam[0] = max(diam[0], cur + l)
l = max(l, cur)
return l
for _ in range(int(input())):
n, a, b, da, db = [int(i) for i in input().split()]
global g... | FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUN... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys as _sys
ALICE = "Alice"
BOB = "Bob"
MAX_GRAPH_SIZE = 10**5
def main():
t = int(input())
for i in range(t):
n, a, b, da, db = _read_ints()
a -= 1
b -= 1
graph = [set() for v in range(n)]
for i in range(n - 1):
u, v = _read_ints()
u -= ... | IMPORT ASSIGN VAR STRING ASSIGN VAR STRING ASSIGN VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_C... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
def bfs(graph, start_ver):
visited = set()
queue = [[start_ver, 0]]
visited.add(start_ver)
ans_way_length, ans_ver = 0, 1
while queue:
ver = queue[0]
queue = queue[1:]
for n... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER WHILE VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
LI = lambda: list(map(int, sys.stdin.readline().strip("\n").split()))
MI = lambda: map(int, sys.stdin.readline().strip("\n").split())
SI = lambda: sys.stdin.readline().strip("\n")
II = lambda: int(sys.stdin.readline().strip("\n"))
for _ in range(II()):
n, a, b, da, db = MI()
g = {i: [] for i in rang... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VA... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | from sys import stdin
input = stdin.readline
q = int(input())
for _ in range(q):
n, sa, sb, a, b = map(int, input().split())
sa -= 1
sb -= 1
nbr = [[] for i in range(n)]
for i in range(n - 1):
x, y = map(int, input().split())
x -= 1
y -= 1
nbr[x].append(y)
nb... | ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n, a, b, da, db = map(int, input().split())
EDGE = [[] for i in range(n + 1)]
for i in range(n - 1):
x, y = map(int, input().split())
EDGE[x].append(y)
EDGE[y].append(x)
if db <= da * 2:
print(... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
ii = lambda: sys.stdin.readline().strip()
idata = lambda: [int(x) for x in ii().split()]
def bfs(graph, start_ver):
visited = set()
queue = [[start_ver, 0]]
visited.add(start_ver)
ans_way_length, ans_ver = 0, start_ver
while queue:
ver = queue.pop(0)
for new_ver in grap... | IMPORT ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST LIST VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR VAR VAR LIS... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, a, b, da, db = map(int, input().split())
dic = {}
dis = {}
for i in range(1, n + 1):
dic[i] = []
dis[i] = 0
for i in range(n - 1):
x, y = map(int, input().split())
dic[x].append(y)
dic[y].... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR LIST ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUN... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
readline = sys.stdin.readline
def parorder(Edge, p):
N = len(Edge)
par = [0] * N
par[p] = -1
stack = [p]
order = []
visited = set([p])
ast = stack.append
apo = order.append
while stack:
vn = stack.pop()
apo(vn)
for vf in Edge[vn]:
if ... | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | diameter = 0
def dfs(u, tree, depth):
global diameter
length = 0
level[u] = depth
isCheck[u] = True
for vertex in tree[u]:
if isCheck[vertex] != True:
isCheck[vertex] = True
cur = dfs(vertex, tree, depth + 1) + 1
diameter = max(diameter, cur + length)
... | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = iter(sys.stdin.read().splitlines()).__next__
def furthest(graph, source):
S = [(source, 0)]
furthest_node = source
furthest_dist = 0
discovered = [False] * len(graph)
while S:
u, dist = S.pop()
if dist > furthest_dist:
furthest_node = u
f... | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR LIST VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR WHILE VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR EXPR FUNC_CALL VAR... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
for f in range(int(input())):
n, a, b, da, db = map(int, input().split())
neig = [0] * n
for i in range(n):
neig[i] = [0]
for i in range(n - 1):
vertexa, vertexb = map(int, input().split())
vertexa -= 1
vertexb -= 1
neig[vert... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LIST NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | def melysegi(x):
latatlan.remove(int(x))
for i in ellista[x]:
if i in latatlan:
melyseg[i] = melyseg[x] + 1
melysegi(i)
def melysegi2(x):
latatlan2.remove(int(x))
for i in ellista[x]:
if i in latatlan2:
melyseg2[i] = melyseg2[x] + 1
melys... | FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EX... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, sa, sb, da, db = map(int, input().split())
e = {}
g = 0
if 2 * da >= db:
exec((n - 1) * "input();")
print("Alice")
continue
for i in range(n):
e[i] = []
for i in range(n - 1):
u, v = m... | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT ASSIGN VAR NUMBER IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER STRING EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR LI... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
sys.setrecursionlimit(10**5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II():
return int(sys.stdin.readline())
def MI():
return map(int, sys.stdin.readline().split())
def MI1():
return map(int1, sys.stdin.readline().split())
def LI():
return list(map(int, sys... | IMPORT EXPR FUNC_CALL VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
n, a, b, da, db = map(int, input().split())
C = [list(map(int, input().split())) for j in range(n - 1)]
for j in range(n - 1):
for k in range(2):
C[j][k] -= 1
a -= 1
b -= 1
M = [[] for j in range(n)]
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | from sys import stdin, stdout
get_string = lambda: stdin.readline().strip("\n")
get_intmap = lambda: map(int, get_string().split(" "))
def testcase():
n, a, b, da, db = get_intmap()
adj = [[] for i in range(n + 1)]
for i in range(n - 1):
u, v = get_intmap()
adj[u].append(v)
adj[v]... | ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR V... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | def Diameter(x):
v[x] = True
stack = [x]
while stack:
a = stack.pop()
for i in d[a]:
if not v[i]:
v[i] = True
stack.append(i)
dis[i] = dis[a] + 1
def BFS(a):
v[a] = True
q = [a]
while q:
p = q.pop(0)
fo... | FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER ASSIGN VAR LIST VAR WHILE VAR ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR VAR VAR IF VAR VAR EXPR ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | from sys import stdin, stdout
def tree_tag(n, a, b, da, db, dic):
dis = distance(a, -1, b, dic)
if dis <= da:
return "Alice"
ln1 = dfs(1, -1, dic)
ln2 = dfs(ln1[0], -1, dic)
mxpath = ln2[1]
if da * 2 < db and mxpath > da * 2:
return "Bob"
return "Alice"
def distance(node,... | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR RETURN STRING ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER NUMBER VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER RETURN STRING RETURN STRING FUNC_DEF IF VAR VAR RETURN NUMBER FOR VAR VAR VAR IF VA... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | from sys import stdin
for _ in range(int(input())):
n, a, b, da, db = map(int, input().split())
a -= 1
b -= 1
go = [[] for _ in range(n)]
for _ in range(n - 1):
x, y = map(int, stdin.readline().split())
x -= 1
y -= 1
go[x].append(y)
go[y].append(x)
MAX = ... | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
def minp():
return sys.stdin.readline().strip()
def mint():
return int(minp())
def mints():
return map(int, minp().split())
def solve():
n, a, b, da, db = mints()
e = [[] for i in range(n + 1)]
for i in range(n - 1):
u, v = mints()
e[u].append(v)
e[v].a... | IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.readline
t = int(input())
for rrr in range(t):
n, a, b, da, db = list(map(int, input().split()))
a -= 1
b -= 1
if da >= db:
for _ in range(n - 1):
x, y = list(map(int, input().split()))
print("Alice")
else:
N = [[] for _ in range(n)]
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR F... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | gans = []
for _ in range(int(input())):
n, a, b, da, db = map(int, input().split())
a -= 1
b -= 1
u = []
for i in range(n):
u.append([])
for i in range(n - 1):
v1, v2 = map(lambda x: int(x) - 1, input().split())
u[v1].append(v2)
u[v2].append(v1)
ind = a
q ... | ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUM... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | from sys import stdin
def input():
return stdin.readline().strip()
tests = int(input())
for t in range(tests):
n, a, b, da, db = list(map(int, input().split()))
edge_ls = [[] for _ in range(n + 1)]
for _ in range(n - 1):
e1, e2 = list(map(int, input().split()))
edge_ls[e1].append(e2)... | FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL V... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | def solve(n, a, b, da, db, G):
if 2 * da >= db:
print("Alice")
return
dist = [-1] * n
stk = [a]
dist[a] = 0
while stk:
x = stk.pop()
for y in G[x]:
if dist[y] == -1:
dist[y] = 1 + dist[x]
stk.append(y)
if dist[b] <= da:
... | FUNC_DEF IF BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR NUMBER WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN ... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
class node:
def __init__(self, i):
self.i = i
self.lvl1 = 0
self.lvl2 = 0
self.neighbour = []
def dfs1(n, p, visited):
visited[n] = 1
for i in p[n].neighbour:
if visited[i.i] == 0:
i.lvl1 = p[n].lvl1 + 1
dfs1(i.i, p, visited)
... | IMPORT CLASS_DEF FUNC_DEF ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FUNC_DEF ASSIGN VAR VAR NUMBER FOR VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | import sys
input = sys.stdin.buffer.readline
T = int(input())
def f(x, y):
dg = 10**6
if x == 0:
return y
elif x < dg:
if x > y:
return y * dg + x
else:
return x * dg + y
else:
xs, xf = divmod(x, dg)
if xs < y:
xs = y
... | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER IF VAR NUMBER RETURN VAR IF VAR VAR IF VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR RETURN VAR IF VAR VAR RETURN BIN_OP BIN_OP... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | t = int(input())
depth = [(0) for _ in range(200050)]
for _ in range(t):
n, a, b, da, db = list(map(int, input().split(" ")))
edges = [[] for _ in range(n + 2)]
for i in range(n - 1):
u, v = list(map(int, input().split(" ")))
edges[u].append(v)
edges[v].append(u)
diameter = 0
... | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR F... |
Alice and Bob are playing a fun game of tree tag.
The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges.
Initially, Alice is located at vertex $a$, and Bob at vertex $b$. They take turns alternately, and Alice makes... | from sys import stdin
class Input:
def readline(self):
return stdin.readline().strip()
def read_int(self):
return int(self.readline())
def read_list(self):
return self.readline().split()
def test_cases(self):
cases = self.read_int()
for case in range(cases):... | CLASS_DEF FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR VAR CLASS_DEF FUNC_DEF ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASS... |
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th ho... | n, m, k = input().split(" ")
n = int(n)
m = int(m)
k = int(k)
ind = []
pre = []
for _ in range(n):
s = input()
ind.append([])
for i, c in enumerate(s):
if c == "1":
ind[-1].append(i)
for i in range(n):
pre.append([])
for j in range(k + 1):
pre[i].append([])
if len... | ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FOR VAR VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR NUMBER VAR FO... |
Ivan is a student at Berland State University (BSU). There are n days in Berland week, and each of these days Ivan might have some classes at the university.
There are m working hours during each Berland day, and each lesson at the university lasts exactly one hour. If at some day Ivan's first lesson is during i-th ho... | R = lambda: map(int, input().split())
n, m, k = R()
cls = [list(i for i, x in enumerate(map(int, input())) if x) for _ in range(n)]
dp = [([n * m] * (k + 1)) for i in range(n + 1)]
dp.append([0] * (k + 1))
for i in range(n):
row = cls[i]
c2l = [m + 1] * (m + 1)
c2l[0] = row[-1] - row[0] + 1 if row else 0
... | ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP VAR VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST NU... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.