Cod sursa(job #961832)

Utilizator a_h1926Heidelbacher Andrei a_h1926 Data 12 iunie 2013 23:11:54
Problema Nowhere-zero Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.58 kb
#include <cstdio>
#include <cmath>
#include <cassert>

#include <algorithm>
#include <vector>
#include <unordered_map>

using namespace std;

typedef long long int64;

const int MAX_V = 100005;
const int MAX_E = 350005;

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 {
        if (x != other.x)
            return x < other.x;
        return y < other.y;
    }

    bool operator==(const Edge &other) const {
        return (x == other.x && y == other.y);
    }

    class HashCode {
      public:
        int64 operator()(const Edge &edge) const {
            return edge.x + 1LL * Base * edge.y;
        }
      private:
        static const int Base = 100003;
    };
};

Point Points[MAX_V], Center;
vector<int> G[MAX_V];
Edge Edges[MAX_E];
int V, E;
//unordered_map<Edge, int, Edge::HashCode> Index, Next;

class Compare {
  public:
    bool operator()(const int &x, const int &y) const {
        return atan2(Points[x].y - Center.y, Points[x].x - Center.y) < atan2(Points[y].y - Center.y, Points[y].x - Center.x);
    }
};

void BuildGraph() {
    for (int x = 1; x <= V; ++x) {
        if (G[x].empty())
            continue;
        Center = Points[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);
    for (int i = 1; i <= V; ++i)
        assert(scanf("%lf %lf", &Points[i].x, &Points[i].y) == 2);
    for (int i = 1; i <= E; ++i) {
        int x, y; assert(scanf("%d %d", &x, &y) == 2);
        Edges[i] = Edge(x, y);
        /*Index[Edge(x, y)] = Index[Edge(y, x)] = i;
        Flow[Edge(x, y)] = Flow[Edge(y, x)] = 0;*/
        G[x].push_back(y); G[y].push_back(x);
    }
}

void Print() {
    assert(freopen("nowhere-zero.out", "w", stdout));
    for (int i = 1; i <= E; ++i) {
        //if (Flow[Edges[i]] < 0)
            //swap(Edges[i].x, Edges[i].y);
        printf("%d %d %d\n", Edges[i].x, Edges[i].y, 0/*Flow[Edges[i]]*/);
    }
}

int main() {
    Read();
    Solve();
    Print();
    return 0;
}