Submission #1139373

#TimeUsernameProblemLanguageResultExecution timeMemory
1139373mariacCheap flights (LMIO18_pigus_skrydziai)C++20
100 / 100
1424 ms109644 KiB
#include <bits/stdc++.h>

using namespace std;
const int NMAX = 3e5;
int n, m;
vector <pair<int,  unsigned long long>> graph[NMAX+1];
vector <unsigned long long> sum(NMAX+1, 0);
unsigned long long stea_max = 0;
bitset <NMAX+1> vis;
map <pair<int, int>, unsigned long long> mat;
unsigned long long maxim(unsigned long long a, unsigned long long b)
{
    if(a>=b)
        return a;
    return b;
}
void read()
{
    int a, b;
    unsigned long long c;
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        cin>>a>>b>>c;
        graph[a].push_back({b, c});
        graph[b].push_back({a, c});
        sum[a]+=c;
        sum[b]+=c;
        stea_max = maxim(stea_max, sum[a]);
        stea_max = maxim(stea_max, sum[b]);
        mat[{a, b}] = c;
        mat[{b, a}] = c;
    }
}
unsigned long long rez3;
void dfs(int node, int parent)
{
    vis[node] = 1;
    for(auto [next, price]:graph[node])
    {
        if( parent!=node && next!=parent && mat.find({next, parent})!=mat.end() )//am detectat ciclu
        {
            rez3  = maxim(rez3, mat[{next, node}] + mat[{parent, node}] + mat[{parent, next}]);
        }
        if(vis[next] == 0)
        {
            dfs(next, node);
        }
    }
}
int main()
{
    read();
    for(int i=1; i<=n; i++)
    {
        if(vis[i]==0)
            dfs(i, i);
    }
    cout<<maxim(stea_max, rez3);
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...