Submission #498917

#TimeUsernameProblemLanguageResultExecution timeMemory
498917aurimsCheap flights (LMIO18_pigus_skrydziai)C++14
0 / 100
121 ms262148 KiB
#include <bits/stdc++.h> #define debug cout << "alio\n" #define pb push_back #define ll long long using namespace std; struct miestas { vector<int> kaimynai; vector<ll> pelnas; }; vector<miestas> miestai; int main() { int N, M; cin >> N >> M; miestai.resize(N); for(int i = 0; i < N; i++) { miestai[i].pelnas.resize(N); for(int j = 0; j < N; j++) { miestai[i].pelnas[j] = -1; } } for(int i = 0; i < M; i++) { int a, b; ll p; cin >> a >> b >> p; miestai[a-1].kaimynai.pb(b-1); miestai[b-1].kaimynai.pb(a-1); miestai[a-1].pelnas[b-1] = p; miestai[b-1].pelnas[a-1] = p; } ll mx = -1; for(int i = 0; i < N; i++) { if(miestai[i].kaimynai.empty()) continue; ll sum_tr = 0; ll sum_zv = 0; // perrenkam zvaigzdes for(int sidx : miestai[i].kaimynai) { sum_zv += miestai[i].pelnas[sidx]; } // perrenkam trikampius for(int j = 0; j < miestai[i].kaimynai.size()-1; j++) { int kaim1 = miestai[i].kaimynai[j]; int kaim2 = miestai[i].kaimynai[j+1]; if(miestai[kaim1].pelnas[kaim2] != -1) // jeigu i-tojo miesto kaimynai j ir j+1 irgi turi kelia, tai susidaro trikampis sum_tr = miestai[i].pelnas[kaim1]+miestai[i].pelnas[kaim2]+miestai[kaim1].pelnas[kaim2]; } if(sum_zv > sum_tr) if(sum_zv > mx) mx = sum_zv; else if(sum_tr > mx) mx = sum_tr; } cout << mx << '\n'; }

Compilation message (stderr)

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:51:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   51 |   for(int j = 0; j < miestai[i].kaimynai.size()-1; j++)
      |                  ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:58:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   58 |   if(sum_zv > sum_tr)
      |     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...