-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathcirculatie.cpp
52 lines (47 loc) · 1004 Bytes
/
circulatie.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
# include <fstream>
# include <algorithm>
# include <vector>
# include <cstring>
# define NR 100005
using namespace std;
ifstream f("circulatie.in");
ofstream g("circulatie.out");
vector <int> v[NR];
struct elem {
int x, y;
}M[3*NR];
int i,j,n,m,x,y, cuplate;
int M1[NR], M2[NR], ap[NR];
bool match (int k)
{
if (ap[k]) return 0;
ap[k]=1;
for (int i=0; i<v[k].size(); ++i) {
if (! M2[v[k][i]] || match(M2[v[k][i]])) {
M1[k]=v[k][i];
M2[v[k][i]]=k;
return 1;
}
}
return 0;
}
int main ()
{
f>>n;
for (i=1; i<=3*n; ++i) {
f>>M[i].x>>M[i].y;
v[M[i].x].push_back(M[i].y);
}
cuplate=1;
while (cuplate) {
memset (ap, 0, sizeof(ap)); cuplate=0;
for (i=1; i<=n; ++i)
if (! M1[i]) cuplate+=match(i);
}
for (i=1; i<=3*n; ++i) {
x=M[i].x; y=M[i].y; g<<x<<" "<<y<<" ";
if (M1[x]==y) g<<"-2\n";
else g<<"1\n";
}
return 0;
}