This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
import sys
# Redirect stdin
#sys.stdin = open('contest.in', 'r')
# Redirect stdout
#sys.stdout = open('contest.out', 'w')
n, m, r, t, k = map(int, input().split())
graph ={}
matching = [-1] * m
degree = [0] * n
for i in range(n):
if graph.get(i)==None:
graph[i]=[]
for _ in range(k):
u, v = map(int, input().split())
u -= 1
v -= 1
graph[u].append(v)
for u in range(m):
if matching[u] == -1:
for v in range(n):
if u in graph[v] and matching[u] == -1:
matching[u] = v
degree[v] += 1
break
for u in range(m):
if matching[u] != -1:
for v in range(n):
if u in graph[v] and matching[u] !=v and degree[matching[u]]>(degree[v]+1):
degree[matching[u]]-=1
matching[u] = v
degree[v] += 1
penalty = 0
res = []
for v in range(n):
b=(degree[v]*(2*3+(degree[v]-1)*3))//2
while(b>t):
degree[v]-=1
b=(degree[v]*(2*3+(degree[v]-1)*3))//2
for u in range(m):
if matching[u] != -1 and degree[matching[u]]:
penalty += degree[matching[u]] * r
degree[matching[u]] -= 1
res.append((matching[u] + 1, u + 1, degree[matching[u]] * r))
res.sort(key=lambda x:(x[2],x[0]))
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... |