답안 #313651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
313651 2020-10-16T13:53:08 Z GioChkhaidze Cheap flights (LMIO18_pigus_skrydziai) C++14
100 / 100
1314 ms 97692 KB
#include <bits/stdc++.h>
 
#define ll long long
#define pb push_back
#define F first
#define S second
 
using namespace std;
 
const int N=3e5+5;

int n,m;
map < int , int > f[N];
vector < pair < int , ll > > v[N];

main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL),cout.tie(NULL);
  
  cin>>n>>m;
  for (int i=1; i<=m; i++) {
    int a,b,c;
    cin>>a>>b>>c;
    v[a].pb({b,c});
    v[b].pb({a,c});
    f[a][b]=max(f[a][b],c);
    f[b][a]=max(f[b][a],c);
  }
  
  ll ans=0;
  for (int i=1; i<=n; i++) {
    ll res=0;
    pair < int , ll > M1={-1,-1},M2={-1,-1};
    for (int j=0; j<v[i].size(); j++) {
      res+=v[i][j].S;
      if (v[i][j].S>M1.S) M2=M1,M1=v[i][j];
        else
      if (v[i][j].S>M2.S) M2=v[i][j];
    }
    
    ans=max(ans,res);
    if (M1.F==-1 || M2.F==-1)
      continue;
    
    ans=max(ans,M1.S+M2.S+f[M1.F][M2.F]);
  }
  
  cout<<ans<<"\n";
}

Compilation message

pigus_skrydziai.cpp:16:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   16 | main() {
      |      ^
pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int j=0; j<v[i].size(); j++) {
      |                   ~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 21504 KB Output is correct
2 Correct 16 ms 21504 KB Output is correct
3 Correct 15 ms 21504 KB Output is correct
4 Correct 15 ms 21504 KB Output is correct
5 Correct 16 ms 21504 KB Output is correct
6 Correct 28 ms 24448 KB Output is correct
7 Correct 15 ms 21504 KB Output is correct
8 Correct 15 ms 21504 KB Output is correct
9 Correct 15 ms 21504 KB Output is correct
10 Correct 15 ms 21504 KB Output is correct
11 Correct 15 ms 21504 KB Output is correct
12 Correct 15 ms 21504 KB Output is correct
13 Correct 15 ms 21504 KB Output is correct
14 Correct 14 ms 21504 KB Output is correct
15 Correct 15 ms 21504 KB Output is correct
16 Correct 15 ms 21504 KB Output is correct
17 Correct 15 ms 21504 KB Output is correct
18 Correct 16 ms 21632 KB Output is correct
19 Correct 17 ms 21888 KB Output is correct
20 Correct 15 ms 21504 KB Output is correct
21 Correct 15 ms 21504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 15 ms 21504 KB Output is correct
2 Correct 16 ms 21504 KB Output is correct
3 Correct 15 ms 21504 KB Output is correct
4 Correct 15 ms 21504 KB Output is correct
5 Correct 16 ms 21504 KB Output is correct
6 Correct 28 ms 24448 KB Output is correct
7 Correct 15 ms 21504 KB Output is correct
8 Correct 15 ms 21504 KB Output is correct
9 Correct 15 ms 21504 KB Output is correct
10 Correct 15 ms 21504 KB Output is correct
11 Correct 15 ms 21504 KB Output is correct
12 Correct 15 ms 21504 KB Output is correct
13 Correct 15 ms 21504 KB Output is correct
14 Correct 14 ms 21504 KB Output is correct
15 Correct 15 ms 21504 KB Output is correct
16 Correct 15 ms 21504 KB Output is correct
17 Correct 15 ms 21504 KB Output is correct
18 Correct 16 ms 21632 KB Output is correct
19 Correct 17 ms 21888 KB Output is correct
20 Correct 15 ms 21504 KB Output is correct
21 Correct 15 ms 21504 KB Output is correct
22 Correct 1314 ms 97692 KB Output is correct
23 Correct 430 ms 93176 KB Output is correct
24 Correct 34 ms 24696 KB Output is correct
25 Correct 20 ms 22400 KB Output is correct
26 Correct 20 ms 22400 KB Output is correct
27 Correct 17 ms 21888 KB Output is correct
28 Correct 447 ms 51960 KB Output is correct
29 Correct 132 ms 33272 KB Output is correct
30 Correct 247 ms 39544 KB Output is correct
31 Correct 16 ms 21632 KB Output is correct
32 Correct 15 ms 21632 KB Output is correct
33 Correct 463 ms 96112 KB Output is correct
34 Correct 388 ms 88056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 47224 KB Output is correct
2 Correct 530 ms 84188 KB Output is correct
3 Correct 165 ms 42232 KB Output is correct
4 Correct 317 ms 61472 KB Output is correct
5 Correct 697 ms 76920 KB Output is correct
6 Correct 102 ms 38392 KB Output is correct
7 Correct 179 ms 69316 KB Output is correct
8 Correct 201 ms 68216 KB Output is correct
9 Correct 17 ms 21632 KB Output is correct
10 Correct 106 ms 38520 KB Output is correct
11 Correct 270 ms 69084 KB Output is correct
12 Correct 199 ms 55416 KB Output is correct
13 Correct 15 ms 21504 KB Output is correct
14 Correct 167 ms 36216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 187 ms 47224 KB Output is correct
2 Correct 530 ms 84188 KB Output is correct
3 Correct 165 ms 42232 KB Output is correct
4 Correct 317 ms 61472 KB Output is correct
5 Correct 697 ms 76920 KB Output is correct
6 Correct 102 ms 38392 KB Output is correct
7 Correct 179 ms 69316 KB Output is correct
8 Correct 201 ms 68216 KB Output is correct
9 Correct 17 ms 21632 KB Output is correct
10 Correct 106 ms 38520 KB Output is correct
11 Correct 270 ms 69084 KB Output is correct
12 Correct 199 ms 55416 KB Output is correct
13 Correct 15 ms 21504 KB Output is correct
14 Correct 167 ms 36216 KB Output is correct
15 Correct 446 ms 52740 KB Output is correct
16 Correct 454 ms 51816 KB Output is correct
17 Correct 523 ms 55580 KB Output is correct
18 Correct 689 ms 63424 KB Output is correct
19 Correct 214 ms 37348 KB Output is correct
20 Correct 722 ms 70132 KB Output is correct
21 Correct 536 ms 86776 KB Output is correct
22 Correct 351 ms 64632 KB Output is correct
23 Correct 527 ms 63452 KB Output is correct
24 Correct 314 ms 43976 KB Output is correct
25 Correct 646 ms 70136 KB Output is correct
26 Correct 688 ms 65200 KB Output is correct
27 Correct 718 ms 63352 KB Output is correct
28 Correct 15 ms 21504 KB Output is correct
29 Correct 16 ms 21504 KB Output is correct
30 Correct 15 ms 21504 KB Output is correct
31 Correct 15 ms 21504 KB Output is correct
32 Correct 16 ms 21504 KB Output is correct
33 Correct 28 ms 24448 KB Output is correct
34 Correct 15 ms 21504 KB Output is correct
35 Correct 15 ms 21504 KB Output is correct
36 Correct 15 ms 21504 KB Output is correct
37 Correct 15 ms 21504 KB Output is correct
38 Correct 15 ms 21504 KB Output is correct
39 Correct 15 ms 21504 KB Output is correct
40 Correct 15 ms 21504 KB Output is correct
41 Correct 14 ms 21504 KB Output is correct
42 Correct 15 ms 21504 KB Output is correct
43 Correct 15 ms 21504 KB Output is correct
44 Correct 15 ms 21504 KB Output is correct
45 Correct 16 ms 21632 KB Output is correct
46 Correct 17 ms 21888 KB Output is correct
47 Correct 15 ms 21504 KB Output is correct
48 Correct 15 ms 21504 KB Output is correct
49 Correct 1314 ms 97692 KB Output is correct
50 Correct 430 ms 93176 KB Output is correct
51 Correct 34 ms 24696 KB Output is correct
52 Correct 20 ms 22400 KB Output is correct
53 Correct 20 ms 22400 KB Output is correct
54 Correct 17 ms 21888 KB Output is correct
55 Correct 447 ms 51960 KB Output is correct
56 Correct 132 ms 33272 KB Output is correct
57 Correct 247 ms 39544 KB Output is correct
58 Correct 16 ms 21632 KB Output is correct
59 Correct 15 ms 21632 KB Output is correct
60 Correct 463 ms 96112 KB Output is correct
61 Correct 388 ms 88056 KB Output is correct