Skip to content

Instantly share code, notes, and snippets.

@koosaga
Last active December 10, 2023 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koosaga/30fd0a986d8193d2da2de989ccd22c05 to your computer and use it in GitHub Desktop.
Save koosaga/30fd0a986d8193d2da2de989ccd22c05 to your computer and use it in GitHub Desktop.
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 = zeros(Int, n, n)
C = [parse(Int64, x) for x in split(readline(io))]
for i in 1:n
for j in 1:n
adj[i, j] = 6969
end
end
for j in 1:m
u, v = [parse(Int, x) for x in split(readline(io))]
adj[u, v] = adj[v, u] = 1
end
for x in 1:n
adj[x, x] = 0
end
for x in 1:n
for y in 1:n
for z in 1:n
adj[y, z] = min(adj[y, z], adj[y, x] + adj[x, z])
end
end
end
for x in 1:n
for y in 1:n
if adj[x, y] <= k
adj[x, y] = 1
else
adj[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(adj[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