Submission #23941679
Source Code Expand
import sys
input = sys.stdin.readline
def main():
n = int(input())
a = [list(map(int, input().split())) for _ in range(n)]
valid = [[True for j in range(n)] for i in range(n)]
m = int(input())
for _ in range(m):
x, y = [int(i) - 1 for i in input().split()]
valid[x][y] = False
valid[y][x] = False
inf = 1 << 30
dp = [[inf for j in range(n)] for i in range(1 << n)]
for i in range(n):
dp[1 << i][i] = a[i][0]
for i in range(1, 1 << n):
bc = sum(i >> j & 1 for j in range(n))
for j in range(n):
for k in range(n):
if valid[j][k] and (i >> k & 1) == 0:
dp[i | 1 << k][k] = min(dp[i | 1 << k][k],
dp[i][j] + a[k][bc])
ans = min(dp[-1])
print(ans if ans < inf else -1)
if __name__ == "__main__":
main()
Submission Info
| Submission Time | |
|---|---|
| Task | 032 - AtCoder Ekiden(★3) |
| User | riantkb |
| Language | Python (3.8.2) |
| Score | 3 |
| Code Size | 894 Byte |
| Status | AC |
| Exec Time | 67 ms |
| Memory | 9312 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 3 / 3 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt |
| All | 00_sample_01.txt, 00_sample_02.txt, 00_sample_03.txt, 10_small_n_01.txt, 10_small_n_02.txt, 10_small_n_03.txt, 50_random_01.txt, 50_random_02.txt, 50_random_03.txt, 50_random_04.txt, 50_random_05.txt, 50_random_06.txt, 50_random_07.txt, 50_random_08.txt, 50_random_09.txt, 50_random_10.txt, 50_random_11.txt, 50_random_12.txt, 50_random_13.txt, 50_random_14.txt, 50_random_15.txt, 60_max_m_01.txt, 60_max_m_02.txt, 60_min_m_01.txt, 60_min_m_02.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00_sample_01.txt | AC | 25 ms | 8968 KiB |
| 00_sample_02.txt | AC | 20 ms | 9252 KiB |
| 00_sample_03.txt | AC | 25 ms | 9072 KiB |
| 10_small_n_01.txt | AC | 27 ms | 9124 KiB |
| 10_small_n_02.txt | AC | 20 ms | 9192 KiB |
| 10_small_n_03.txt | AC | 20 ms | 8960 KiB |
| 50_random_01.txt | AC | 26 ms | 9136 KiB |
| 50_random_02.txt | AC | 18 ms | 9120 KiB |
| 50_random_03.txt | AC | 18 ms | 9196 KiB |
| 50_random_04.txt | AC | 29 ms | 8960 KiB |
| 50_random_05.txt | AC | 19 ms | 8956 KiB |
| 50_random_06.txt | AC | 21 ms | 8964 KiB |
| 50_random_07.txt | AC | 26 ms | 9072 KiB |
| 50_random_08.txt | AC | 30 ms | 9132 KiB |
| 50_random_09.txt | AC | 44 ms | 9184 KiB |
| 50_random_10.txt | AC | 48 ms | 9124 KiB |
| 50_random_11.txt | AC | 40 ms | 9248 KiB |
| 50_random_12.txt | AC | 52 ms | 9312 KiB |
| 50_random_13.txt | AC | 45 ms | 9184 KiB |
| 50_random_14.txt | AC | 43 ms | 9312 KiB |
| 50_random_15.txt | AC | 53 ms | 9024 KiB |
| 60_max_m_01.txt | AC | 37 ms | 9252 KiB |
| 60_max_m_02.txt | AC | 37 ms | 9016 KiB |
| 60_min_m_01.txt | AC | 67 ms | 9064 KiB |
| 60_min_m_02.txt | AC | 66 ms | 9200 KiB |