Submission #5733494
Source Code Expand
# 最小値が端点でないと、隣接とswapして矛盾。
# 最小値は端点としてよい。
# 端点のどれでもよい。
# あとは帰納的に
N = int(input())
score = 0
edge = [set() for _ in range(N+1)]
for _ in range(N-1):
a,b = map(int,input().split())
edge[a].add(b)
edge[b].add(a)
C = [int(x) for x in input().split()]
deg = [len(x) for x in edge]
# degree1の頂点全体
deg_1 = [i for i,x in enumerate(deg) if x == 1]
D = [None]*(N+1)
C.sort(reverse = True)
M = sum(C) - C[0] # score
while deg_1:
v = deg_1.pop()
if not deg_1:
D[v] = C.pop()
break
w = edge[v].pop()
edge[w].remove(v)
deg[w] -= 1
if deg[w] == 1:
deg_1.append(w)
D[v] = C.pop()
print(M)
print(' '.join(map(str,D[1:])))
Submission Info
| Submission Time | |
|---|---|
| Task | D - Maximum Sum of Minimum |
| User | maspy |
| Language | Python (3.4.3) |
| Score | 500 |
| Code Size | 791 Byte |
| Status | AC |
| Exec Time | 75 ms |
| Memory | 7276 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 500 / 500 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | example0.txt, example1.txt |
| All | 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, example0.txt, example1.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 000.txt | AC | 43 ms | 5364 KiB |
| 001.txt | AC | 68 ms | 7156 KiB |
| 002.txt | AC | 45 ms | 5236 KiB |
| 003.txt | AC | 68 ms | 7028 KiB |
| 004.txt | AC | 43 ms | 5236 KiB |
| 005.txt | AC | 69 ms | 7028 KiB |
| 006.txt | AC | 43 ms | 5236 KiB |
| 007.txt | AC | 68 ms | 6900 KiB |
| 008.txt | AC | 43 ms | 5236 KiB |
| 009.txt | AC | 75 ms | 7028 KiB |
| 010.txt | AC | 42 ms | 5236 KiB |
| 011.txt | AC | 67 ms | 7028 KiB |
| 012.txt | AC | 43 ms | 5236 KiB |
| 013.txt | AC | 67 ms | 7028 KiB |
| 014.txt | AC | 43 ms | 5236 KiB |
| 015.txt | AC | 70 ms | 7028 KiB |
| 016.txt | AC | 46 ms | 5236 KiB |
| 017.txt | AC | 70 ms | 7028 KiB |
| 018.txt | AC | 43 ms | 5236 KiB |
| 019.txt | AC | 69 ms | 7028 KiB |
| 020.txt | AC | 43 ms | 5236 KiB |
| 021.txt | AC | 69 ms | 7028 KiB |
| 022.txt | AC | 42 ms | 5108 KiB |
| 023.txt | AC | 66 ms | 7276 KiB |
| example0.txt | AC | 18 ms | 3064 KiB |
| example1.txt | AC | 17 ms | 3064 KiB |