Submission #500593

# Submission time Handle Problem Language Result Execution time Memory
500593 2021-12-31T13:51:11 Z GenericAccount Cheap flights (LMIO18_pigus_skrydziai) C++17
28 / 100
492 ms 48124 KB
#include <bits/stdc++.h>

using namespace std;

int N, M;
// N-miestu skaicius, M-poru skaicius

struct Best {
  int to;
  int pelnas;
  Best() {
    this->to = -1;
    this->pelnas = -1;
  }
};

map<pair<int, int>, int>pelnas;

void checkForBest(int a, int b, int pelnas, vector<pair<Best, Best>> & pelningiausi) {
  if (pelnas > pelningiausi[a].first.pelnas) {
    pelningiausi[a].second = pelningiausi[a].first;
    pelningiausi[a].first.to = b;
    pelningiausi[a].first.pelnas = pelnas;
  }
  else if(pelnas>pelningiausi[a].second.pelnas){
     pelningiausi[a].second.to = b;
     pelningiausi[a].second.pelnas = pelnas;
  }
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  vector<pair<Best, Best>> pelningiausi(N);
  vector<int> visas_pelnas(N);
  int a, b, p;
  for (int i = 0; i < M; i++) {
    cin >> a >> b >> p;

    visas_pelnas[a - 1] += p;
    visas_pelnas[b - 1] += p;
    checkForBest(a - 1, b - 1, p, pelningiausi);
    checkForBest(b - 1, a - 1, p, pelningiausi);
    if (b > a)
      swap(a, b);
    pelnas[make_pair(a - 1, b - 1)] = p;
  }

  int best = 0;
  for (int peln : visas_pelnas) {
    best = max(best, peln);
  }

  for (int i = 0; i < pelningiausi.size(); i++) {
      b = min(pelningiausi[i].first.to, pelningiausi[i].second.to);
    if (b != -1) {
      a = max(pelningiausi[i].first.to, pelningiausi[i].second.to);
      int tri=pelningiausi[i].first.pelnas + pelningiausi[i].second.pelnas + pelnas[make_pair(a, b)];
      best=max(best, tri);
    }
  }
  // for(pair<Best, Best> bp : pelningiausi){
  //   cout<<bp.first.to<<" "<<bp.first.pelnas<<endl;
  //   cout<<bp.second.to<<" "<<bp.second.pelnas<<endl;
  //   cout<<"--------------"<<endl;
  // }

  cout << best << endl;
}

Compilation message

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:55:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<Best, Best> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |   for (int i = 0; i < pelningiausi.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 1740 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 308 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 0 ms 308 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 8 ms 1740 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 0 ms 304 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 0 ms 332 KB Output is correct
14 Correct 0 ms 308 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 0 ms 308 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 492 ms 40528 KB Output is correct
23 Incorrect 211 ms 40260 KB Output isn't correct
24 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 103 ms 17712 KB Output is correct
2 Correct 341 ms 48124 KB Output is correct
3 Correct 81 ms 16124 KB Output is correct
4 Correct 196 ms 30576 KB Output is correct
5 Correct 431 ms 37572 KB Output is correct
6 Correct 46 ms 9232 KB Output is correct
7 Correct 153 ms 35636 KB Output is correct
8 Correct 159 ms 29368 KB Output is correct
9 Correct 4 ms 6220 KB Output is correct
10 Correct 42 ms 9308 KB Output is correct
11 Correct 122 ms 25028 KB Output is correct
12 Correct 102 ms 18372 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 59 ms 7688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 17712 KB Output is correct
2 Correct 341 ms 48124 KB Output is correct
3 Correct 81 ms 16124 KB Output is correct
4 Correct 196 ms 30576 KB Output is correct
5 Correct 431 ms 37572 KB Output is correct
6 Correct 46 ms 9232 KB Output is correct
7 Correct 153 ms 35636 KB Output is correct
8 Correct 159 ms 29368 KB Output is correct
9 Correct 4 ms 6220 KB Output is correct
10 Correct 42 ms 9308 KB Output is correct
11 Correct 122 ms 25028 KB Output is correct
12 Correct 102 ms 18372 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 59 ms 7688 KB Output is correct
15 Correct 0 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 308 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 8 ms 1740 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 304 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 0 ms 332 KB Output is correct
28 Correct 0 ms 308 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 0 ms 204 KB Output is correct
31 Correct 0 ms 308 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 460 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 204 KB Output is correct
36 Correct 492 ms 40528 KB Output is correct
37 Incorrect 211 ms 40260 KB Output isn't correct
38 Halted 0 ms 0 KB -