QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#278352 | #5558. Formula Flatland | jzh# | WA | 6ms | 30272kb | C++20 | 2.3kb | 2023-12-07 15:05:35 | 2023-12-07 15:05:36 |
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 = 7e5 + 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 j = 0; j < eids.size(); j++) {
int nxt = (j + 1) % eids.size();
int eu = eids[j] ^ 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 = 4;
for (int i = 0; i < 2 * m; i++) {
ans = min(ans, siz[find(i)]);
// cout <<" siz " << find(i) <<" -> " << siz[find(i)] << endl;
}
cout << ans << endl;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 29468kb
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: 6ms
memory: 29584kb
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: 29096kb
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: 5ms
memory: 30272kb
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: -100
Wrong Answer
time: 0ms
memory: 28752kb
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:
4
result:
wrong answer 1st lines differ - expected: '5', found: '4'