Submission #461326

#TimeUsernameProblemLanguageResultExecution timeMemory
461326idasCheap flights (LMIO18_pigus_skrydziai)C++11
100 / 100
1736 ms101224 KiB
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i = (begin); i < (end); i++)
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define SZ(x) ((int)((x).size()))
#define LE(vec) vec[vec.size()-1]
#define TSTS int t; cin >> t; while(t--)solve()

const int INF = 1e9;
const long long LINF = 1e18;
const long double PI = asin(1)*2;
const int MOD = 1e9+7;

using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef map<int, int> mii;
typedef long long ll;
typedef long double ld;

void setIO()
{
    FAST_IO;
}

void setIO (string s)
 {
    setIO();
 	freopen((s+".in").c_str(),"r",stdin);
 	freopen((s+".out").c_str(),"w",stdout);
}

const int N=3e5+10, M=5e5+10;

int n, m;
ll cn[N], ans;
map<pii, ll> con;
set<pii, greater<pii>> ad[N];

int main()
{
    setIO();
    cin >> n >> m;
    FOR(i, 0, m)
    {
        int a, b; ll c;
        cin >> a >> b >> c;
        cn[a-1]+=c;
        cn[b-1]+=c;
        ad[a-1].insert({c, b-1});
        ad[b-1].insert({c, a-1});
        con[{min(a-1, b-1), max(a-1, b-1)}]=c;
    }

    FOR(i, 0, n) ans=max(ans, cn[i]);

    FOR(i, 0, n)
    {
        int in=2;
        int k=-1, b=-1;
        for(auto[x, y] : ad[i]){
            if(in){
                if(in==2){
                    k=y;
                }
                else{
                    b=y;
                }
                in--;
            }
            else break;
        }

        ll val=con[{min(i, k), max(i, k)}]+
        con[{min(i, b), max(i, b)}]+
        con[{min(k, b), max(k, b)}];
        ans=max(ans, val);
    }

    cout << ans;
}

Compilation message (stderr)

pigus_skrydziai.cpp: In function 'int main()':
pigus_skrydziai.cpp:64:17: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |         for(auto[x, y] : ad[i]){
      |                 ^
pigus_skrydziai.cpp: In function 'void setIO(std::string)':
pigus_skrydziai.cpp:32:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   32 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pigus_skrydziai.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...