제출 #313651

#제출 시각아이디문제언어결과실행 시간메모리
313651GioChkhaidzeCheap flights (LMIO18_pigus_skrydziai)C++14
100 / 100
1314 ms97692 KiB
#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";
}

컴파일 시 표준 에러 (stderr) 메시지

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++) {
      |                   ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...