-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1601.cpp
More file actions
26 lines (22 loc) · 703 Bytes
/
Copy path1601.cpp
File metadata and controls
26 lines (22 loc) · 703 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
class Solution {
int degree[21] = {0};
int res = 0;
void rec(const vector<vector<int>> &req, int cur = 0, int cnt = 0, int dirty = 0) {
if (cnt + (req.size() - cur) < res) return;
if (cur == req.size()) {
if (dirty) return;
res = max(res, cnt);
return;
}
rec(req, cur + 1, cnt, dirty);
if (degree[req[cur][0]]++ == 0) dirty++;
if (--degree[req[cur][1]] == 0) dirty--;
rec(req, cur + 1, cnt + 1, dirty);
degree[req[cur][0]]--, degree[req[cur][1]]++;
}
public:
int maximumRequests(int n, const vector<vector<int>> &requests) {
rec(requests);
return res;
}
};