QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#658118#6765. Don't Really Like How The Story EndsCangShuV#TL 9ms10584kbPython3723b2024-10-19 16:11:432024-10-19 16:11:43

Judging History

你现在查看的是最新测评结果

  • [2024-10-19 16:11:43]
  • 评测
  • 测评结果:TL
  • 用时:9ms
  • 内存:10584kb
  • [2024-10-19 16:11:43]
  • 提交

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)
        

Details

Tip: Click on the bar to expand more detailed information

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
...

result: