-
Notifications
You must be signed in to change notification settings - Fork 10
/
ASSIGN1.cpp
92 lines (78 loc) 路 1.57 KB
/
ASSIGN1.cpp
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef unsigned long long ull;
#define X first
#define Y second
#define pb push_back
#define EL printf("\n")
#define sz(A) (int) A.size()
#define FOR(i,l,r) for (int i=l;i<=r;i++)
#define FOD(i,r,l) for (int i=r;i>=l;i--)
#define faster ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int N = 201;
int n, c[N][N], matchX[N], matchY[N], trace[N];
vector<int> a[N];
int f[N*N], ans;
int findPath() {
queue<int> st;
FOR(i,1,n) trace[i] = 0;
FOR(i,1,n)
if (matchX[i] == 0) st.push(i);
while (! st.empty()) {
int u = st.front();
st.pop();
for (auto v : a[u]) {
if (trace[v]) continue;
trace[v] = u;
if (matchY[v] == 0) return v;
st.push(matchY[v]);
}
}
return -1;
}
bool solve(int time) {
FOR(i,1,n) {
a[i].clear();
matchX[i] = matchY[i] = 0;
}
FOR(i,1,n)
FOR(j,1,n)
if (c[i][j] <= time) a[i].pb(j);
for (;;) {
int v = findPath();
if (v == -1) break;
while (v != 0) {
int u = trace[v];
int k = matchX[u];
matchX[u] = v;
matchY[v] = u;
v = k;
}
}
FOR(i,1,n)
if (matchX[i] == 0) return false;
return true;
}
int main() {
// freopen("INP.TXT", "r", stdin);
// freopen("OUT.TXT", "w", stdout);
scanf("%d", &n);
FOR(i,1,n)
FOR(j,1,n)
scanf("%d", &c[i][j]), f[++f[0]] = c[i][j];
sort(f+1, f+f[0]+1);
f[0] = unique(f+1, f+f[0]+1)-f-1;
int L = 1, R = f[0];
while (L <= R) {
int mid = (L+R)/2;
if (solve(f[mid])) {
ans = f[mid];
R = mid-1;
} else
L = mid+1;
}
printf("%d\n", ans);
return 0;
}