Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define st first
- #define nd second
- #define pb push_back
- #define mkp make_pair
- #define lwbnd lower_bound
- #define upbnd upper_bound
- #define FOR(i,a,b) for(int i=(a);i<=(b);++i)
- #define FORS(i,a,b) for(int i=(a);i<(b);++i)
- #define ALL(x) x.begin(),x.end()
- #define SZ(x) ((int)(x).size())
- #define MOD 1000000007 //998244353
- #define maxn 500005
- typedef long long ll;
- typedef pair<int,int> PII;
- typedef vector<int> VI;
- typedef vector<PII> VPII;
- const int INF=0x3f3f3f3f;
- int Duration, Intersections_n, Streets_n, Cars_n, extra;
- typedef struct {
- int time;
- int in_front;
- int roads_counter;
- int position;
- vector<string> roads;
- } Car;
- typedef struct {
- int start;
- int end;
- int initial_cars;
- int duration;
- int total_cars;
- int total_average;
- string name;
- } Street;
- typedef struct {
- vector<string> inc_streets;
- } Intersection;
- map <string, Street> Streets;
- vector<Car> Cars;
- vector<Intersection> Intersections;
- void average() {
- Street str;
- for (auto car : Cars) {
- int time = 0;
- int done = 0;
- for (auto road : car.roads) {
- if (done == 0) {
- time += car.in_front;
- done = 1;
- continue;
- }
- str = Streets[road];
- time += str.duration;
- Streets[road].total_cars += 1;
- }
- for (auto road : car.roads) {
- Streets[road].total_average += time;
- }
- car.time = time;
- }
- }
- int main()
- {
- cin.tie(0);
- ios_base::sync_with_stdio(0);
- freopen("c.txt","r",stdin);
- freopen("c.out","w",stdout);
- int x, y, duration;
- string nm;
- cin >> Duration >> Intersections_n >> Streets_n >> Cars_n >> extra;
- Intersections.resize(Intersections_n);
- FORS (i, 0, Streets_n) {
- Street str;
- cin >> str.start >> str.end >> str.name >> str.duration;
- str.initial_cars = 0;
- Intersections[str.end].inc_streets.push_back(str.name);
- Streets[str.name] = str;
- }
- FORS (i, 0, Cars_n) {
- Car cr;
- string aux;
- cin >> cr.roads_counter;
- cin >> aux;
- cr.roads.push_back(aux);
- cr.in_front = Streets[aux].initial_cars;
- Streets[aux].initial_cars += 1;
- FORS (i, 1, cr.roads_counter) {
- cin >> aux;
- cr.roads.push_back(aux);
- }
- Cars.push_back(cr);
- }
- average();
- vector<long long> answers[Intersections_n];
- for (int i = 0; i < Intersections.size(); i++) {
- int counter = 0;
- vector<long long> values (Intersections[i].inc_streets.size(), 0LL);
- long long total = 0LL;
- for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
- Street street = Streets[Intersections[i].inc_streets[j]];
- if (street.total_cars == 0) {
- values[j] = -2;
- continue;
- }
- if (Duration - street.total_average / street.total_cars < 0) {
- values[j] = -1;
- } else if (street.total_average != 0){
- values[j] = 1LL * street.total_cars * street.total_cars / street.total_average;
- total += 1LL * street.total_cars * street.total_cars / street.total_average;
- counter++;
- }
- }
- if (counter == 0 ) {
- Intersections_n--;
- continue;
- }
- for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
- if (values[j] != -1 && values[j] != -2) {
- values[j] = 1 + (values[j] * 10LL) / (total * Duration);
- }
- }
- for (auto it: values) {
- answers[i].push_back(it);
- }
- }
- cout << Intersections_n << '\n';
- for (int i = 0; i < Intersections.size(); i++) {
- int counter = 0;
- for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
- if(answers[i][j] > 0)
- counter++;
- }
- if (counter != 0) {
- cout << i << "\n";
- cout << counter << "\n";
- for (int j = 0; j < Intersections[i].inc_streets.size(); j++) {
- if(answers[i][j] > 0)
- cout << Intersections[i].inc_streets[j] << ' ' << answers[i][j] << '\n';
- else if (answers[i][j] == 0) {
- cout << Intersections[i].inc_streets[j] << ' ' << '1' << '\n';
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement