编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#29918 #2070. 选课 Wrong Answer 0 155 ms 2964 K Python 2 / 2.3 K 192023212026 2025-03-15 22:05:36
import sys
from collections import deque

def main():
    n = int(sys.stdin.readline())
    c = []
    for _ in range(n):
        ci = int(sys.stdin.readline())
        c.append(ci)
    
    # 构建邻接表,使用集合避免重复边
    adj = [set() for _ in range(n)]
    for i in range(n):
        parts = list(map(int, sys.stdin.readline().split()))
        ai = parts[0]
        courses = parts[1:]
        for course in courses:
            j = course - 1  # 转换为0-based
            adj[i].add(j)
            adj[j].add(i)
    
    # 转换为列表以便后续处理
    adj = [list(s) for s in adj]
    
    visited = [False] * n
    total = 0
    
    for i in range(n):
        if not visited[i]:
            # BFS找到连通分量
            q = deque()
            q.append(i)
            visited[i] = True
            component = []
            while q:
                u = q.popleft()
                component.append(u)
                for v in adj[u]:
                    if not visited[v]:
                        visited[v] = True
                        q.append(v)
            
            k = len(component)
            if k == 1:
                total += c[component[0]]
            elif k == 2:
                total += max(c[component[0]], c[component[1]])
            else:
                # 寻找中心节点
                center = None
                for u in component:
                    if len(adj[u]) == k - 1:
                        # 检查其他节点是否度数均为1
                        valid = True
                        for v in component:
                            if v == u:
                                continue
                            if len(adj[v]) != 1:
                                valid = False
                                break
                        if valid:
                            center = u
                            break
                if center is not None:
                    sum_leaves = sum(c[v] for v in component if v != center)
                    total += max(c[center], sum_leaves)
                else:
                    # 根据题目条件,这不可能发生
                    pass
    print(total)

if __name__ == "__main__":
    main()
子任务 #1
Wrong Answer
得分:0
测试点 #1
Wrong Answer
得分:0
用时:16 ms
内存:2864 KiB

输入文件(a1.in

64546
346
911
232
260
204
354
770
686
656
180
492
760
332
73
994
129
292
221
732
<1304086 bytes omitted>

答案文件(a1.out

21980830

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #2
Wrong Answer
得分:0
用时:17 ms
内存:2880 KiB

输入文件(a2.in

87763
360
122
644
448
64
834
996
456
514
928
337
622
831
299
150
359
616
816
573
<1785910 bytes omitted>

答案文件(a2.out

29779119

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #3
Wrong Answer
得分:0
用时:15 ms
内存:2964 KiB

输入文件(a3.in

97101
785
659
469
214
368
744
560
280
670
968
816
272
430
41
500
483
72
216
714

<1980327 bytes omitted>

答案文件(a3.out

33348125

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #4
Wrong Answer
得分:0
用时:15 ms
内存:2876 KiB

输入文件(a4.in

96463
15
109
882
404
711
196
826
474
68
958
551
512
664
306
99
868
80
392
1000
5
<1967031 bytes omitted>

答案文件(a4.out

32960896

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #5
Wrong Answer
得分:0
用时:15 ms
内存:2860 KiB

输入文件(a5.in

84245
394
737
934
484
602
32
127
444
543
384
860
925
416
248
896
432
198
964
400
<1712626 bytes omitted>

答案文件(a5.out

28721378

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #6
Wrong Answer
得分:0
用时:15 ms
内存:2856 KiB

输入文件(a6.in

32637
135
269
88
586
80
410
895
360
898
480
37
686
182
520
877
879
124
167
932
4
<644317 bytes omitted>

答案文件(a6.out

11132180

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #7
Wrong Answer
得分:0
用时:17 ms
内存:2896 KiB

输入文件(a7.in

60741
802
467
361
954
776
84
314
830
338
187
984
625
182
638
194
530
298
546
710
<1225125 bytes omitted>

答案文件(a7.out

20739417

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #8
Wrong Answer
得分:0
用时:14 ms
内存:2912 KiB

输入文件(a8.in

15201
908
169
997
372
674
852
20
800
436
627
620
732
866
516
456
620
806
422
260
<288163 bytes omitted>

答案文件(a8.out

5185111

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #9
Wrong Answer
得分:0
用时:16 ms
内存:2916 KiB

输入文件(a9.in

28101
858
8
80
704
892
252
373
456
748
158
520
237
7
866
976
16
539
288
960
420
<551205 bytes omitted>

答案文件(a9.out

9617080

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1
测试点 #10
Wrong Answer
得分:0
用时:15 ms
内存:2888 KiB

输入文件(a10.in

20685
792
775
818
562
12
216
332
200
872
338
111
432
388
298
96
712
84
256
577
3
<399364 bytes omitted>

答案文件(a10.out

7062131

标准错误流

  File "/sandbox/2/a.py", line 11
SyntaxError: Non-ASCII character '\xe6' in file /sandbox/2/a.py on line 11, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details

Special Judge 信息

Files user_out and answer differ

系统信息

Exited with return code 1