Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <algorithm>
- #include <vector>
- #include <functional>
- #include <map>
- #include <set>
- using namespace std;
- //метод update для построения графа: компонента связности = станция
- //трелки идут от более ранних электричек к более поздним
- //color: 0 - белый, 1 - серый, 2 - черный
- void dfs(int v, vector <vector <int> >& gr, vector <int>& TopSort, vector <int>& color) {
- if (color[v] == 2 || color[v] == 1) return;
- color[v] = 1;
- for (int u : gr[v]) {
- dfs(u, gr, TopSort, color);
- }
- color[v] = 2;
- TopSort.push_back(v);
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int N;
- cin >> N;
- vector < pair <pair <int, int> , pair <int, int> > > TRAIN(N+1); //A {station, time}, B {station, time}
- for (int i = 1; i < N + 1; ++i) {
- int from, to, from_time, pace, to_time;
- cin >> from >> to >> from_time >> pace;
- to_time = (to - from) * pace + from_time;
- pair <int, int> A = { from, from_time };
- pair <int, int> B = { to, to_time };
- TRAIN[i] = { A,B };
- }
- /*cout << '\n';
- for (auto x : TRAIN) {
- auto A = x.first;
- auto B = x.second;
- cout << A.first << ' ' << A.second << '\n';
- cout << B.first << ' ' << B.second << '\n' << '\n';
- }cout << '\n';*/
- vector <vector <pair <int, int> > > STAT; //stations
- set <int> used_stat;
- for (int i = 1; i < N+1; ++i) {
- auto A = TRAIN[i].first;
- int from = A.first;
- if (used_stat.find(from) == used_stat.end()) {
- vector <pair <int, int> > stat_from;
- int from_time = A.second;
- stat_from.push_back({from_time, i });
- for (int j = 1; j < N + 1 && j != i; ++j) {
- auto A_some = TRAIN[j].first;
- int from_some = A.first;
- int from_time_some = A.second;
- if (from_some == from && used_stat.find(from_some) == used_stat.end()) {
- stat_from.push_back({ from_time_some, from_some });
- }
- auto B_some = TRAIN[j].second;
- int to_some = B_some.first;
- int to_time_some = B_some.second;
- if (to_some == from && used_stat.find(to_some) == used_stat.end()) {
- stat_from.push_back({ to_time_some, to_some });
- }
- }
- sort(stat_from.begin(), stat_from.end());
- STAT.push_back(stat_from);
- used_stat.insert(from);
- }
- auto B = TRAIN[i].second;
- int to = B.first;
- if (used_stat.find(to) == used_stat.end()) {
- vector <pair <int, int> > stat_to;
- int to_time = B.second;
- stat_to.push_back({ to_time, i });
- for (int j = 1; j < N + 1 && j != i; ++j) {
- auto A_some = TRAIN[j].first;
- int from_some = A_some.first;
- int from_time_some = A.second;
- if (from_some == to && used_stat.find(from_some) == used_stat.end()) {
- stat_to.push_back({ from_time_some, from_some });
- }
- auto B_some = TRAIN[j].second;
- int to_some = B.first;
- int to_time_some = B.second;
- if (to_some == to && used_stat.find(to_some) == used_stat.end()) {
- stat_to.push_back({ to_time_some, to_some });
- }
- }
- sort(stat_to.begin(), stat_to.end());
- STAT.push_back(stat_to);
- used_stat.insert(to);
- }
- }
- cout << "ONE\n";
- vector <vector <int> > gr(N+1);
- for (int i = 0; i < STAT.size(); ++i) {
- for (int j = 0; j < (int)STAT[i].size() - 1; ++j) {
- int faster = STAT[i][j].second;
- int slower = STAT[i][j + 1].second;
- cout << "slower = " << slower << '\n';
- gr[faster].push_back(slower);
- }
- }
- for (int i = 1; i < N + 1; ++i) {
- for (auto j : gr[i]) {
- cout << j << ' ';
- }cout << '\n';
- }cout << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement