Submission #460637

# Submission time Handle Problem Language Result Execution time Memory
460637 2021-08-09T08:04:53 Z idas Cheap flights (LMIO18_pigus_skrydziai) C++11
0 / 100
657 ms 68520 KB
#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=4e5+10, M=5e5+10;

ll n, m;
bool v[N];
ll cn[N], ans;
set<ll> ad[N];
map<pair<ll, ll>, ll> con;

void dfs(ll u, ll pst)
{
    v[u]=true;
    for(auto it : ad[u]){
        if(it==pst) continue;
        if(!v[it]){
            dfs(it, u);
        }
        else{
            if(ad[it].count(pst)){
                ll val=con[{min(pst, u), max(pst, u)}]
                +con[{min(it, u), max(it, u)}]
                +con[{min(it, pst), max(it, pst)}];
                ans=max(ans, val);
            }
        }
    }
}

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

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

    dfs(0, -1);

    cout << ans;
}

Compilation message

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 time Memory Grader output
1 Correct 12 ms 19020 KB Output is correct
2 Correct 11 ms 19020 KB Output is correct
3 Correct 12 ms 19020 KB Output is correct
4 Correct 10 ms 19116 KB Output is correct
5 Correct 10 ms 19112 KB Output is correct
6 Correct 43 ms 22244 KB Output is correct
7 Correct 10 ms 19020 KB Output is correct
8 Correct 10 ms 19020 KB Output is correct
9 Correct 13 ms 19100 KB Output is correct
10 Correct 12 ms 19124 KB Output is correct
11 Incorrect 11 ms 19148 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 12 ms 19020 KB Output is correct
2 Correct 11 ms 19020 KB Output is correct
3 Correct 12 ms 19020 KB Output is correct
4 Correct 10 ms 19116 KB Output is correct
5 Correct 10 ms 19112 KB Output is correct
6 Correct 43 ms 22244 KB Output is correct
7 Correct 10 ms 19020 KB Output is correct
8 Correct 10 ms 19020 KB Output is correct
9 Correct 13 ms 19100 KB Output is correct
10 Correct 12 ms 19124 KB Output is correct
11 Incorrect 11 ms 19148 KB Output isn't correct
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 277 ms 44924 KB Output is correct
2 Correct 657 ms 68520 KB Output is correct
3 Incorrect 168 ms 35504 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 277 ms 44924 KB Output is correct
2 Correct 657 ms 68520 KB Output is correct
3 Incorrect 168 ms 35504 KB Output isn't correct
4 Halted 0 ms 0 KB -