이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
from collections import defaultdict
import sys
# Read input values
num_workers, num_tasks, penalty_rate, total_time, num_avail_assign = map(int, sys.stdin.readline().split())
# Create an adjacency list to represent the graph
graph = defaultdict(list)
# Store the matching and degree arrays
matching = [-1] * num_tasks
degree = [0] * num_workers
# Array to track visited vertices during DFS
used = [0] * (num_workers + 1)
# Variable to track the current DFS iteration
T = 0
# Depth-first search function to find augmenting paths
def try_dfs(v, deg):
global T
if used[v] == T:
return False
used[v] = T
if degree[v] > deg + 1:
return True
for u in graph[v]:
if try_dfs(matching[u], deg):
degree[matching[u]] -= 1
matching[u] = v
degree[v] += 1
return True
return False
# Read the edges of the graph and build the adjacency list
for _ in range(num_avail_assign):
u, v = map(int, sys.stdin.readline().split())
u -= 1
v -= 1
graph[u].append(v)
# Initialize the matching and degree arrays
for u in range(num_tasks):
if matching[u] == -1:
for v in range(num_workers):
if u in graph[v] and matching[u] == -1:
matching[u] = v
degree[v] += 1
# Iterate until no more augmenting paths can be found
updated = True
while updated:
ds = [(degree[v], v) for v in range(num_workers)]
ds.sort()
T += 1
updated = any(try_dfs(v, degree[v]) for _, v in ds)
# Calculate penalty and collect the selected assignments
penalty = 0
res = []
for v in range(num_workers):
degree[v] = min(degree[v], total_time // penalty_rate)
for u in range(num_tasks):
if matching[u] != -1 and degree[matching[u]]:
penalty += degree[matching[u]] * penalty_rate
degree[matching[u]] -= 1
res.append((matching[u] + 1, u + 1, degree[matching[u]] * penalty_rate))
# Print the output
print(len(res), penalty)
for el in res:
print(el[0], el[1], el[2])
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |