-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathbile.cpp
49 lines (45 loc) · 1.13 KB
/
bile.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
# include <fstream>
# include <algorithm>
# define NR 300*300
using namespace std;
ifstream f("bile.in");
ofstream g("bile.out");
int i,j,n,m,Rx,Ry,nr,nrv,lv,cv,maxim;
int R[NR], X[NR], Y[NR], maxx[NR], H[NR];
int dx[]={-1, 0, 1, 0};
int dy[]={0, 1, 0, -1};
int numar (int i, int j) {
return (i-1)*n + j;
}
int radacina (int k) {
while (k!=R[k]) k=R[k];
return k;
}
int main ()
{
f>>n;
for (i=1; i<=n*n; ++i)
f>>X[i]>>Y[i];
for (i=n*n; i>=1; --i) {
nr=numar(X[i], Y[i]);
R[nr]=nr; H[nr]=1;
maxx[i]=maxim;
maxim=max(maxim, 1);
for (j=0; j<4; ++j) {
lv=X[i] + dx[j]; cv=Y[i] + dy[j];
if (1<=lv && lv<=n && 1<=cv && cv<=n) {
nrv=numar (lv, cv);
Rx=radacina(nr);
Ry=radacina(nrv);
if (Rx && Ry && Rx!=Ry) {
if (H[Rx]>H[Ry]) R[Ry]=Rx, H[Rx]+=H[Ry];
else R[Rx]=Ry, H[Ry]+=H[Rx];
}
maxim=max(maxim, max(H[Rx], H[Ry]));
}
}
}
for (i=1; i<=n*n; ++i)
g<<maxx[i]<<"\n";
return 0;
}