Pagini recente » Cod sursa (job #1754677) | Cod sursa (job #2870643) | Cod sursa (job #34980) | Cod sursa (job #2395006) | Cod sursa (job #962265)
Cod sursa(job #962265)
#include <cstdio>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <vector>
#include <unordered_map>
using namespace std;
typedef long long int64;
class Point {
public:
double x, y;
Point() {}
Point(const double x, const double y) {
this->x = x;
this->y = y;
}
};
class Edge {
public:
int x, y;
Edge() {}
Edge(const int x, const int y) {
this->x = x;
this->y = y;
}
bool operator==(const Edge &other) const {
return (x == other.x && y == other.y);
}
class HashCode {
public:
int operator()(const Edge &object) const {
return (1LL * object.x * Base + object.y) % U;
}
private:
static const int Base = 100003;
static const int U = 666013;
};
};
vector<Point> Points;
vector<double> Alpha;
vector<vector<int>> G;
int V, E;
unordered_map<Edge, int, Edge::HashCode> Next;
vector<Edge> Edges;
class Compare {
public:
bool operator()(const int &x, const int &y) const {
return Alpha[x] < Alpha[y];
}
};
void BuildGraph() {
for (int x = 0; x < V; ++x) {
if (G[x].empty())
continue;
for (auto &y: G[x])
Alpha[y] = atan2(Points[y].y - Points[x].y, Points[y].x - Points[x].x);
sort(G[x].begin(), G[x].end(), Compare());
G[x].push_back(G[x].front());
for (int i = 0; i + 1 < static_cast<int>(G[x].size()); ++i)
Next[Edge(G[x][i], x)] = G[x][i + 1];
}
}
void Solve() {
BuildGraph();
}
void Read() {
assert(freopen("nowhere-zero.in", "r", stdin));
assert(scanf("%d %d", &V, &E) == 2);
G.resize(V);
Points.resize(V);
Alpha.resize(V);
Edges.resize(E);
for (int i = 0; i < V; ++i)
assert(scanf("%lf %lf", &Points[i].x, &Points[i].y) == 2);
for (int i = 0; i < E; ++i) {
int x, y; assert(scanf("%d %d", &x, &y) == 2);
--x; --y;
Edges[i] = Edge(x, y);
G[x].push_back(y); G[y].push_back(x);
}
}
void Print() {
assert(freopen("nowhere-zero.out", "w", stdout));
for (int i = 0; i < E; ++i) {
printf("%d %d %d\n", Edges[i].x + 1, Edges[i].y + 1, 0);
}
}
int main() {
Read();
Solve();
Print();
return 0;
}