QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278235 | #5558. Formula Flatland | jzh# | WA | 79ms | 34740kb | C++20 | 2.3kb | 2023-12-07 14:00:40 | 2023-12-07 14:00:41 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Point {
public:
ll x, y;
ll operator^(Point &a) {
return x * a.y - y * a.x;
}
};
struct argcmp {
bool operator()(Point &a, Point &b) {
auto quad = [](Point &a) {
if (a.y < 0) return 1;
if (a.y > 0) return 4;
if (a.x < 0)return 5;
if (a.x > 0)return 3;
};
int qa = quad(a), qb = quad(b);
if (qa != qb)return qa < qb;
ll t = a ^ b;
return t > 0;
}
};
const int N = 6e5 + 5;
struct E {
int u, v;
Point a;
} e[N];
int fa[N];
int siz[N];
int find(int u) {
while (fa[u] != u) u = fa[u] = fa[fa[u]];
return u;
}
int x[N], y[N];
vector<int> G[N];
int main() {
ios::sync_with_stdio(false);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> x[i] >> y[i];
}
for (int i = 0; i < 2 * m; i += 2) {
int u, v;
cin >> u >> v;
Point a = {x[u] - x[v], y[u] - y[v]};
Point b = {x[v] - x[u], y[v] - y[u]};
e[i] = {u, v, b};
e[i + 1] = {v, u, a};
G[u].push_back(i);
G[v].push_back(i + 1);
fa[i] = i, fa[i + 1] = i + 1;
siz[i] = siz[i + 1] = 1;
}
for (int i = 1; i <= n; i++) {
vector<int> eids = G[i];
auto cmp = [&](int u, int v) {
argcmp cp;
return cp(e[u].a, e[v].a);
};
sort(eids.begin(), eids.end(), cmp);
for (int i = 0; i < eids.size(); i++) {
int nxt = (i + 1) % eids.size();
int eu = eids[i] ^ 1, ev = eids[nxt];
// cout <<" conn " << eu<<" and " << ev << endl;
// cout <<" siz " << siz[find(eu)] <<" , " << siz[find(ev)] << endl;
// cout <<" f " << find(eu) <<","<< find(ev) << endl;
if (find(eu) != find(ev)) {
siz[find(ev)] += siz[find(eu)];
fa[find(eu)] = find(ev);
// cout <<" siz " << find(ev) <<" is " << siz[find(ev)] << endl;
}
}
}
int ans = 1e9;
for(int i=0;i<2*m;i++){
ans = min(ans , siz[find(i)]);
}
cout << ans <<endl;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 17520kb
input:
4 6 0 0 3 0 0 3 1 1 1 2 1 3 1 4 2 3 2 4 3 4
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 17428kb
input:
10 15 1 5 2 1 3 4 4 2 5 3 6 2 7 3 8 1 9 4 11 5 1 2 1 3 1 10 2 4 3 5 4 5 4 6 5 7 6 7 6 8 7 9 8 10 9 10 2 8 3 9
output:
4
result:
ok single line: '4'
Test #3:
score: 0
Accepted
time: 3ms
memory: 17528kb
input:
12 18 0 0 10 10 20 0 15 1 15 4 17 2 13 2 8 7 5 3 8 5 8 6 7 4 1 3 1 4 1 7 2 3 2 5 2 8 3 6 4 5 4 6 5 6 7 9 7 10 8 9 8 11 9 12 10 11 10 12 11 12
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 17532kb
input:
8 12 0 0 12 0 3 2 6 6 6 1 9 2 6 5 6 4 1 2 1 3 1 5 2 4 2 6 3 4 3 8 4 7 5 6 5 8 6 7 7 8
output:
4
result:
ok single line: '4'
Test #5:
score: 0
Accepted
time: 0ms
memory: 17704kb
input:
20 30 0 0 36 0 18 18 5 4 8 3 16 1 20 2 32 3 27 5 29 6 18 17 17 15 15 10 10 2 16 4 20 7 25 4 23 9 19 13 19 8 1 2 2 3 3 4 4 5 5 1 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 6 16 17 17 18 18 19 19 20 20 16 1 6 2 8 3 10 4 12 5 14 7 16 9 17 11 18 13 19 15 20
output:
5
result:
ok single line: '5'
Test #6:
score: 0
Accepted
time: 3ms
memory: 17712kb
input:
12 30 0 0 20 0 10 10 4 3 7 2 9 1 16 3 10 9 10 8 9 4 13 2 12 6 1 2 1 3 1 4 1 5 1 6 2 3 3 4 4 5 5 6 6 2 7 2 7 3 8 3 8 4 9 4 9 5 10 5 10 6 11 6 11 2 7 8 8 9 9 10 10 11 11 7 12 7 12 8 12 9 12 10 12 11
output:
3
result:
ok single line: '3'
Test #7:
score: 0
Accepted
time: 3ms
memory: 17536kb
input:
6 12 0 0 8 0 5 2 4 3 3 1 4 4 1 2 2 3 3 4 4 1 5 1 6 1 5 2 6 2 5 3 6 3 5 4 6 4
output:
3
result:
ok single line: '3'
Test #8:
score: 0
Accepted
time: 3ms
memory: 17476kb
input:
12 18 0 0 20 0 3 2 10 10 5 1 17 2 5 4 6 5 13 6 10 9 9 7 10 8 1 2 1 3 1 5 2 4 2 6 3 4 3 7 4 8 5 6 5 7 6 8 7 8 9 10 9 11 9 12 10 11 10 12 11 12
output:
3
result:
ok single line: '3'
Test #9:
score: 0
Accepted
time: 0ms
memory: 17536kb
input:
12 19 0 0 20 0 10 9 10 10 9 7 8 5 11 8 13 6 11 1 8 4 6 2 8 3 1 2 1 3 1 5 2 4 2 6 3 4 3 7 4 8 5 6 5 7 6 8 7 8 9 10 9 11 9 12 10 11 10 12 11 12 1 9
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 0ms
memory: 17496kb
input:
46 69 0 0 46 2 88 0 49 1 30 4 25 3 44 44 79 8 59 2 50 5 31 6 44 43 55 3 36 5 30 10 23 4 9 8 44 42 72 7 64 3 59 5 53 9 34 7 27 8 12 10 77 9 63 7 55 8 39 6 32 12 32 13 17 7 14 9 45 40 66 4 60 13 58 11 41 7 32 16 21 5 19 6 47 37 71 6 69 5 59 15 45 32 1 3 1 4 1 2 2 5 2 6 3 7 3 8 4 9 4 10 5 11 11 6 7 12 ...
output:
4
result:
ok single line: '4'
Test #11:
score: 0
Accepted
time: 67ms
memory: 32012kb
input:
99994 166652 0 0 164087 24231 16153 1467 80696 7356 55659 5065 130637 4863 178682 544 100912 7558 74630 6795 170587 16557 157941 2412 175028 11309 67128 6109 124070 5465 128321 5070 163029 1979 162531 1996 51885 4712 149664 41288 142160 3814 55444 5040 79209 7222 178706 6943 82464 7501 104751 7227 1...
output:
4
result:
ok single line: '4'
Test #12:
score: 0
Accepted
time: 73ms
memory: 32124kb
input:
99998 166660 0 0 44650 3765 182247 1495 112004 7385 139279 5119 58545 4895 6434 559 91137 7618 118668 6882 30458 2586 29030 2439 20799 1760 126793 6136 65967 5522 61316 5126 23468 1978 24029 2025 143489 4824 76139 6388 46024 3857 139549 5088 113899 7579 12750 1125 110075 7551 87058 7284 116307 7127 ...
output:
5
result:
ok single line: '5'
Test #13:
score: 0
Accepted
time: 73ms
memory: 33936kb
input:
99857 199084 0 0 133841 27313 130867 61811 35938 31076 137395 7465 148228 50647 58797 16554 156910 20181 20200 12984 135370 23638 98039 2116 144490 16863 21807 12052 88572 36832 86716 37327 133565 22794 75471 46343 38269 23447 89136 45968 177375 19185 17108 5990 135669 6753 117358 35927 4138 3357 27...
output:
4
result:
ok single line: '4'
Test #14:
score: 0
Accepted
time: 79ms
memory: 34740kb
input:
99996 199988 0 0 41854 6629 75715 3077 164081 4911 163673 5475 134280 13391 154899 5665 181897 1823 38415 5848 188581 1312 126110 5509 47134 6766 31807 4743 96221 95900 104514 4582 45458 6738 126440 5611 138745 11284 161984 5687 72343 2492 160200 5783 46828 6673 15907 2194 112610 5327 82969 3780 749...
output:
4
result:
ok single line: '4'
Test #15:
score: -100
Wrong Answer
time: 3ms
memory: 17668kb
input:
19 33 0 0 12 11 22 11 11 6 10 1 10 4 11 9 17 17 17 10 17 15 13 12 11 7 17 2 34 0 6 2 17 16 11 8 21 12 13 5 14 3 10 11 1 14 18 16 6 19 9 2 11 2 18 3 15 5 8 3 15 4 1 15 14 5 1 8 17 15 9 10 7 1 17 7 5 6 12 19 18 10 8 16 9 3 6 4 19 13 7 14 13 17 11 16 13 5 2 8 12 17 2 7 12 4
output:
4
result:
wrong answer 1st lines differ - expected: '3', found: '4'