QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#658118 | #6765. Don't Really Like How The Story Ends | CangShuV# | TL | 9ms | 10584kb | Python3 | 723b | 2024-10-19 16:11:43 | 2024-10-19 16:11:43 |
Judging History
answer
from collections import defaultdict
import sys
sys.setrecursionlimit(1000000)
def push(u,v):
g[u].add(v)
def dfs(u):
global go,cnt
if u not in g:
return
for i in gs[u]:
while go<i:
go+=1
cnt+=1
dfs(go-1)
if go==i:
go+=1
for i in range(int(input())):
n,m=map(int,input().split())
cnt=0
g=defaultdict(set)
st=[0 for i in range(n+10)]
push(1,n+1)
for i in range(m):
u,v=map(int,input().split())
u,v=min(u,v),max(u,v)
push(u,v)
gs={k:sorted(v) for k,v in g.items() }
go=2
dfs(1)
print(cnt)
详细
Test #1:
score: 100
Accepted
time: 9ms
memory: 10584kb
input:
3 2 3 1 1 1 2 2 1 4 1 1 4 4 2 1 2 3 4
output:
0 2 1
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
input:
117747 3 7 2 1 3 3 1 3 1 1 3 2 1 1 3 1 4 8 2 3 4 3 3 2 4 2 1 3 2 1 4 3 2 4 3 4 2 3 2 2 3 3 1 1 2 5 1 1 2 2 2 2 1 2 2 2 3 7 2 1 1 2 3 3 3 2 1 2 3 3 3 2 4 5 1 2 3 3 4 4 1 4 2 1 3 1 3 2 1 3 1 1 1 1 1 1 1 6 1 1 1 1 1 1 1 1 1 1 1 1 5 4 2 1 2 5 1 3 3 2 4 7 1 1 2 4 3 2 1 1 1 1 4 2 2 3 5 8 3 3 2 2 4 2 1 4 1...
output:
0 1 1 0 1 1 1 0 0 2 1 1 0 0 2 1 2 0 1 0 2 3 0 0 0 2 1 1 1 0 0 0 1 1 2 1 3 0 1 1 3 1 3 1 0 0 1 2 0 2 0 1 1 0 0 2 0 0 0 1 0 3 0 3 0 0 1 2 0 3 2 0 1 0 1 0 2 3 0 0 1 1 1 0 0 2 1 3 0 1 2 0 0 0 3 0 0 3 1 0 2 0 0 1 1 0 1 0 0 0 0 4 0 0 0 0 0 0 2 0 1 0 0 1 0 0 0 2 0 1 0 0 0 2 1 1 2 2 0 1 0 1 1 1 2 1 1 1 0 0 ...