#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long
#define ull unsigned long long
#define ld long double
// 217
// 44
using namespace std;
const int MAXN = 30000;
struct Match {
vector < vector <int> > g;
vector <int> vis, l, r;
map < pair <int, int>, int > mp;
int n, now;
int ans;
inline void init(int _n) {
n = _n;
g.resize(n + 1);
l.resize(n + 1);
r.resize(n + 1);
vis.resize(n + 1);
ans = now = 0;
}
inline void addEdge(int x, int y) {
g[x].push_back(y);
}
inline void delEdge(int x, int y) {
mp[{x, y}] = 1;
}
bool match(int nod) {
for(auto it : g[nod]) {
if(r[it] == 0 && mp[{nod, it}] == 0) {
l[nod] = it;
r[it] = nod;
return 1;
}
}
vis[nod] = now;
for(auto it : g[nod]) {
if(mp[{nod, it}] == 0 && vis[r[it]] != now && match(r[it])) {
l[nod] = it;
r[it] = nod;
return 1;
}
}
return 0;
}
inline int solve(int m) {
bool flag = 1;
int i;
while(flag) {
flag = 0;
for(i = 1; i <= m; i++) {
if(l[i] == 0) {
flag |= match(i);
}
}
}
for(i = 1; i <= m; i++) {
ans += (l[i] > 0);
}
return ans;
}
}M;
vector <int> g[MAXN + 1];
int main() {
//ifstream cin("A.in");
//ofstream cout("A.out");
int i, n, m, k;
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for(i = 1; i <= k; i++) {
int a, b;
cin >> a >> b;
g[a].push_back(b);
}
Match M;
M.init(n + m);
int pos = 1;
ll ans = 0;
for(i = 1; i <= n; i++) {
bool ok = 0;
while(M.solve(m) < m && pos <= n) {
for(auto it : g[pos]) {
M.addEdge(it, pos + m);
}
pos++;
ok = 1;
}
pos -= ok;
if(M.ans == m) {
ans += n - pos + 1;
}
for(auto it : g[i]) {
M.delEdge(it, i + m);
}
}
cout << ans;
//cin.close();
//cout.close();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
1016 KB |
Output isn't correct |
2 |
Incorrect |
2 ms |
1168 KB |
Output isn't correct |
3 |
Incorrect |
2 ms |
1168 KB |
Output isn't correct |
4 |
Incorrect |
2 ms |
1180 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
1180 KB |
Output isn't correct |
6 |
Incorrect |
2 ms |
1180 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
1284 KB |
Output isn't correct |
8 |
Correct |
3 ms |
1284 KB |
Output is correct |
9 |
Correct |
2 ms |
1360 KB |
Output is correct |
10 |
Correct |
2 ms |
1360 KB |
Output is correct |
11 |
Correct |
2 ms |
1360 KB |
Output is correct |
12 |
Incorrect |
2 ms |
1360 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
1360 KB |
Output isn't correct |
14 |
Incorrect |
2 ms |
1360 KB |
Output isn't correct |
15 |
Incorrect |
2 ms |
1360 KB |
Output isn't correct |
16 |
Incorrect |
2 ms |
1360 KB |
Output isn't correct |
17 |
Incorrect |
2 ms |
1360 KB |
Output isn't correct |
18 |
Incorrect |
3 ms |
1360 KB |
Output isn't correct |
19 |
Incorrect |
4 ms |
1376 KB |
Output isn't correct |
20 |
Incorrect |
3 ms |
1376 KB |
Output isn't correct |
21 |
Correct |
2 ms |
1376 KB |
Output is correct |
22 |
Incorrect |
2 ms |
1376 KB |
Output isn't correct |
23 |
Incorrect |
3 ms |
1376 KB |
Output isn't correct |
24 |
Incorrect |
3 ms |
1376 KB |
Output isn't correct |
25 |
Incorrect |
20 ms |
2092 KB |
Output isn't correct |
26 |
Incorrect |
4 ms |
2092 KB |
Output isn't correct |
27 |
Incorrect |
3 ms |
2092 KB |
Output isn't correct |
28 |
Incorrect |
3 ms |
2092 KB |
Output isn't correct |
29 |
Incorrect |
6 ms |
2092 KB |
Output isn't correct |
30 |
Incorrect |
5 ms |
2092 KB |
Output isn't correct |
31 |
Incorrect |
255 ms |
4820 KB |
Output isn't correct |
32 |
Incorrect |
10 ms |
4820 KB |
Output isn't correct |
33 |
Correct |
5 ms |
4820 KB |
Output is correct |
34 |
Incorrect |
5 ms |
4820 KB |
Output isn't correct |
35 |
Incorrect |
56 ms |
8164 KB |
Output isn't correct |
36 |
Incorrect |
42 ms |
8164 KB |
Output isn't correct |
37 |
Incorrect |
408 ms |
8164 KB |
Output isn't correct |
38 |
Incorrect |
60 ms |
8444 KB |
Output isn't correct |
39 |
Incorrect |
89 ms |
8444 KB |
Output isn't correct |
40 |
Correct |
100 ms |
8444 KB |
Output is correct |
41 |
Incorrect |
148 ms |
8444 KB |
Output isn't correct |
42 |
Incorrect |
64 ms |
8444 KB |
Output isn't correct |
43 |
Incorrect |
72 ms |
8444 KB |
Output isn't correct |
44 |
Incorrect |
144 ms |
8444 KB |
Output isn't correct |
45 |
Incorrect |
290 ms |
8444 KB |
Output isn't correct |
46 |
Incorrect |
889 ms |
9204 KB |
Output isn't correct |
47 |
Incorrect |
240 ms |
9568 KB |
Output isn't correct |
48 |
Incorrect |
232 ms |
9568 KB |
Output isn't correct |
49 |
Incorrect |
1022 ms |
9952 KB |
Output isn't correct |
50 |
Incorrect |
282 ms |
9952 KB |
Output isn't correct |