# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
96059 | Kastanda | Marriage questions (IZhO14_marriage) | C++11 | 380 ms | 1928 KiB |
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<bits/stdc++.h>
#define pb push_back
using namespace std;
const int MAXN = 34004;
int n, m, k, ts, l, r, MC[MAXN], M[MAXN];
vector < int > Adj[MAXN];
queue < int > qu;
bool DFS(int v)
{
if (M[v] == ts)
return 0;
M[v] = ts;
for (int i = 0; i < (int)Adj[v].size() && Adj[v][i] <= r; i++)
if (l <= Adj[v][i] && Adj[v][i] <= r)
if (MC[Adj[v][i]] == -1 || DFS(MC[Adj[v][i]]))
return MC[Adj[v][i]] = v, 1;
return 0;
}
inline void Match()
{
while (qu.size())
{
int v = qu.front();
qu.pop(); ts ++;
if (!DFS(v))
{
qu.push(v);
return ;
}
}
}
int main()
{
scanf("%d%d%d", &n, &m, &k);
for (int i = 1; i <= k; i++)
{
int v, u;
scanf("%d%d", &v, &u);
Adj[u].pb(v);
}
int tot = 0;
memset(MC, -1, sizeof(MC));
for (int i = 1; i <= m; i++)
qu.push(i), sort(Adj[i].begin(), Adj[i].end());
for (l = 1; l <= n; l ++)
{
r = max(r, l); Match();
while (r < n && qu.size())
r ++, Match();
if (qu.size())
break;
tot += n - r + 1;
if (MC[l] != -1)
qu.push(MC[l]), MC[l] = -1;
}
return !printf("%d\n", tot);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |