-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathe.cpp
More file actions
106 lines (93 loc) · 2.33 KB
/
Copy pathe.cpp
File metadata and controls
106 lines (93 loc) · 2.33 KB
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
template<class T> using uset = unordered_set<T>;
template<class T, class U> using umap = unordered_map<T, U>;
template<class T> using mset = multiset<T>;
template<class T, class U> using mmap = multimap<T, U>;
template<class T> using umset = unordered_multiset<T>;
template<class T, class U> using ummap = unordered_multimap<T, U>;
#define REP(i, n, m) for(ll i=n; i<(ll)m; ++i)
#define IREP(i, n, m) for(ll i=n-1; i>=m; --i)
#define rep(i, n) REP(i, 0, n)
#define irep(i, n) IREP(i, n, 0)
#define all(v) v.begin(), v.end()
#define vprint(v) for(auto e:v){cout<<e<<" ";};cout<<endl;
#define vvprint(vv) for(auto v:vv){vprint(v)};
ll gcd(ll n, ll m){
while(true){
if(n<m) swap(n, m);
if(!m) break;
n %= m;
}
return n;
}
class UnionFind{
public:
ll size;
vll v;
UnionFind(ll n){
this->v = vll(n);
rep(i, n) this->v[i] = i;
}
ll root(ll n){
if(n!=v[n]) return v[n] = root(v[n]);
return n;
}
void unite(ll l, ll r){
ll lroot = root(l);
ll rroot = root(r);
if(lroot!=rroot) this->v[rroot] = lroot;
}
};
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << setprecision(20);
ll N, K;
cin >> N >> K;
vll X(N), Y(N);
rep(i, N) cin >> X[i] >> Y[i];
if(K==1){
cout << "Infinity" << endl;
return 0;
}
map<pair<ll, ll>, set<pair<ll, ll>>> m;
rep(i, N) REP(j, i, N){
ll dx = X[j] - X[i];
ll dy = Y[j] - Y[i];
if (abs(dx)>0 && abs(dy)>0) {
ll g = gcd(abs(dx), abs(dy));
dx /= g;
dy /= g;
}
else if(abs(dx)>0) dx /= abs(dx);
else if(abs(dy)>0) dy /= abs(dy);
if(dx<0){
dx = -dx;
dy = -dy;
}
else if(dx==0){
dy = abs(dy);
}
m[{dx, dy}].insert({i, j});
}
ll ans = 0;
for(auto [d, s]: m){
UnionFind uf(N);
for(auto p: s){
uf.unite(p.first, p.second);
}
map<ll, ll> count;
rep(i, N){
++count[uf.root(i)];
}
for(auto [_, k]: count){
if(k>=K) ++ans;
}
}
cout << ans << endl;
}