# ExchangeReserves

596
Crypto Market Insight: Tại sao Dự trữ Sàn giao dịch Xứng đáng được Chú ý hơn Biến động Giá Hàng ngày
Nhiều nhà đầu tư dành hàng giờ để xem biểu đồ giá trong khi bỏ qua một trong những chỉ báo có nhiều thông tin nhất hiện có: dự trữ sàn giao dịch.
Chỉ số này đo lường lượng Bitcoin và các tài sản kỹ thuật số khác còn lại trên các sàn giao dịch tập trung.
Trong thời gian dài hơn, dự trữ sàn giao dịch giảm thường cho thấy các nhà đầu tư đang chuyển tài sản vào ví riêng để nắm giữ dài hạn, làm giảm lượng tài sản có sẵn ngay để bán.
Tuy nhiên, dự trữ tăng có thể chỉ ra rằng nhiều người tham gia hơn
BTC2,70%
Xem bản gốc
post-image
post-image
  • Phần thưởng
  • 20
  • Đăng lại
  • Retweed
sahra_:
```python
import sys
from collections import deque

def solve() -> None:
it = iter(sys.stdin.read().split())
n = int(next(it))
m = int(next(it))

v = [int(next(it)) for _ in range(n)]

out_adj = [[] for _ in range(n)]
in_adj = [[] for _ in range(n)] # reverse graph
for _ in range(m):
a = int(next(it))
b = int(next(it))
out_adj[a].append(b)
in_adj[b].append(a)

outdeg = [len(out_adj[i]) for i in range(n)]

# --------------------------------------------------------------
def check(assign):
"""assign: list of 0/1, 1 means 'a', 0 means 'b'.
returns (cond1_holds, cond2_holds)"""
cond1 = True
for i in range(n):
if assign[i] == 1:
cnt = 0
for j in out_adj[i]:
if assign[j] == 1:
cnt += 1
if cnt != v[i]:
cond1 = False
break
cond2 = True
for i in range(n):
if assign[i] == 0:
cnt = 0
for j in out_adj[i]:
if assign[j] == 0:
cnt += 1
if cnt != v[i]:
cond2 = False
break
return cond1, cond2
# --------------------------------------------------------------

def removal_condition1():
"""Try to find a set S (for condition 1) by iterative removal.
Returns assignment list with 1 for S, 0 for complement."""
in_set = [True] * n
cur = outdeg[:] # number of outgoing edges to current S
q = deque()
in_queue = [False] * n
for i in range(n):
if cur[i] != v[i]:
q.append(i)
in_queue[i] = True

while q:
u = q.popleft()
in_queue[u] = False
if not in_set[u]:
continue
# remove u from S
in_set[u] = False
for w in in_adj[u]:
if in_set[w]:
cur[w] -= 1
if cur[w] != v[w] and not in_queue[w]:
q.append(w)
in_queue[w] = True
return [1 if in_set[i] else 0 for i in range(n)]

def removal_condition2():
"""Symmetrically try to find a set B (for condition 2) by iterative removal.
Returns assignment: 1 for 'a', 0 for 'b', where B is the set of 'b' nodes."""
in_set = [True] * n # initial B = all nodes
cur = outdeg[:] # number of outgoing edges to current B
q = deque()
in_queue = [False] * n
for i in range(n):
if cur[i] != v[i]:
q.append(i)
in_queue[i] = True

while q:
u = q.popleft()
in_queue[u] = False
if not in_set[u]:
continue
in_set[u] = False
for w in in_adj[u]:
if in_set[w]:
cur[w] -= 1
if cur[w] != v[w] and not in_queue[w]:
q.append(w)
in_queue[w] = True
# B = set of nodes where in_set[i] is True (they are 'b')
# assignment: a = complement(B), b = B
return [0 if in_set[i] else 1 for i in range(n)]

# list of candidate assignments
candidates = []

# from removal condition 1
candidates.append(removal_condition1())

# from removal condition 2
candidates.append(removal_condition2())

# trivial: all 'a'
candidates.append([1] * n)
# trivial: all 'b'
candidates.append([0] * n)

for assign in candidates:
c1, c2 = check(assign)
if c1 != c2: # exactly one holds
out = ''.join('a' if assign[i] else 'b' for i in range(n))
print(out)
return

print("No solution")

if __name__ == "__main__":
solve()
```
Xem thêm
Tải thêm

Tham gia cùng 40 M người dùng trong cộng đồng đang phát triển của chúng tôi

⚡️ Tham gia cùng 40 M người dùng trong cuộc thảo luận về cơn sốt tiền điện tử
💬 Tương tác với những nhà sáng tạo hàng đầu mà bạn yêu thích
👍 Xem những điều bạn quan tâm
  • Đã ghim