Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
#include <fstream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <set>
#include <limits>
struct Edge {
int from, to, index;
};
struct Event {
bool opening;
Edge edge;
void dfs(const vector< vector<int> > &edges, vector<int> &colors, int node) {
for (auto &neighbor : edges[node]) {
assert(colors[neighbor] != colors[node]);
if (colors[neighbor] == 0) {
colors[neighbor] = 3 - colors[node];
dfs(edges, colors, neighbor);
}
}
}
int main() {
ifstream cin("aquapark.in");
ofstream cout("aquapark.out");
sort(events.begin(), events.end());
set<pair<int, int> > S;
for (auto &event : events) {
if (event.opening)
S.emplace(event.edge.from, event.edge.index);
else {
bool kept = false;
for (auto it = S.upper_bound(make_pair(event.edge.from,
numeric_limits<int>::max())), jt = it; it != S.end(); it = jt) {
jt = it;
++jt;
conflict[event.edge.index].push_back(it->second);
conflict[it->second].push_back(event.edge.index);
if (kept)
S.erase(it);
else
kept = true;
}
S.erase(make_pair(event.edge.from, event.edge.index));
}
}
if (type == 1) {
for (auto &edge : edges)
cout << edge.from << " " << edge.to << " " << colors[edge.index] <<
"\n";
} else {
int as_power = 1;
for (int i = 0; i < answer; ++i)
as_power = (2 * as_power) % kModulo;
cout << as_power << "\n";
}
}