This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;
const int maxn = 505;
int deg_o[maxn], match_z[maxn];
vector<int> g_o[maxn], g_z[maxn];
int vis_o[maxn], vis_z[maxn];
bool dfs(int o1, int d)
{
if (deg_o[o1] < d - 1) return true;
vis_o[o1] = true;
for (int z : g_o[o1]) if (!vis_z[z] && match_z[z] == o1)
{
vis_z[z] = true;
for (int o2 : g_z[z]) if (!vis_o[o2])
{
if (dfs(o2, d))
{
match_z[z] = o2;
deg_o[o1]--, deg_o[o2]++;
return true;
}
}
}
return false;
}
bool cmp(int o1, int o2)
{
return deg_o[o1] > deg_o[o2];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int no, nz, r, t, k;
cin >> no >> nz >> r >> t >> k;
for (int i = 0; i < k; i++)
{
int o, z;
cin >> o >> z;
g_o[--o].push_back(--z);
g_z[z].push_back(o);
}
vector<int> ord(no);
iota(ord.begin(), ord.end(), 0);
fill(match_z, match_z + nz, -1);
for (int i = 0; i < no; i++) random_shuffle(g_o[i].begin(), g_o[i].end());
for (int i = 0; i < nz; i++) random_shuffle(g_z[i].begin(), g_z[i].end());
for (int i = 0; i < nz; i++) if (!g_z[i].empty())
{
match_z[i] = g_z[i][0];
deg_o[match_z[i]]++;
}
bool change = true;
while (change)
{
change = false;
sort(ord.begin(), ord.end(), cmp);
for (int i = 0; i < no; i++) vis_o[i] = false;
for (int i = 0; i < nz; i++) vis_z[i] = false;
for (int o : ord) if (!vis_o[o])
change |= dfs(o, deg_o[o]);
}
int solved = 0, time = 0;
for (int i = 0; i < no; i++)
{
deg_o[i] = min(deg_o[i], t/r);
solved += deg_o[i];
time += r * (deg_o[i] * (deg_o[i] + 1)) / 2;
}
cout << solved << " " << time << "\n";
for (int i = 0; i < nz; i++) if (match_z[i] != -1 && deg_o[match_z[i]])
{
deg_o[match_z[i]]--;
cout << match_z[i] + 1 << " " << i + 1 << " " << deg_o[match_z[i]] * r << "\n";
}
return 0;
}
# | 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... |