Created
December 10, 2023 00:09
-
-
Save koosaga/c4e4003d9fb12186b001b53ff6183715 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using StaticArrays; | |
using CSV, DataFrames, JuMP, SCIP; | |
io = open("input.txt", "r"); | |
io2 = open("output.txt", "w"); | |
t = parse(Int64, readline(io)); | |
for i in 1:t | |
n, m, k = [parse(Int64, x) for x in split(readline(io))] | |
adj = Vector{Vector{Int64}}(undef, n) | |
C = [parse(Int64, x) for x in split(readline(io))] | |
for i in 1:n | |
adj[i] = Vector{Int64}(undef, 0) | |
end | |
for j in 1:m | |
u, v = [parse(Int, x) for x in split(readline(io))] | |
adj[u] = append!(adj[u], v) | |
adj[v] = append!(adj[v], u) | |
end | |
tt = zeros(Int, n, n) | |
for x in 1:n | |
vis = zeros(Int, n) | |
dist = zeros(Int, n) | |
que = Vector{Int64}(undef, 0) | |
fr = 1 | |
que = append!(que, x) | |
vis[x] = 1 | |
while fr <= length(que) | |
fu = que[fr] | |
fr = fr + 1 | |
for y in adj[fu] | |
if vis[y] == 0 | |
vis[y] = 1 | |
dist[y] = dist[fu] + 1 | |
que = append!(que, y) | |
end | |
end | |
end | |
for y in 1:n | |
if vis[y] == 1 && dist[y] <= k | |
tt[x, y] = 1 | |
else | |
tt[x, y] = 0 | |
end | |
end | |
end | |
m = Model(SCIP.Optimizer) | |
@variable(m, x[1:n], Bin) | |
@objective(m, Min, sum(x[i] * C[i] for i in 1:n)) | |
@constraint(m, c1[i in 1:n], sum(tt[i, j] * x[j] for j in 1:n) >= 1) | |
optimize!(m) | |
z = Int(round(objective_value(m))) | |
println(io2, "Case #$i: $z") | |
flush(io2) | |
end | |
close(io); | |
close(io2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment