Submission #396669

# Submission time Handle Problem Language Result Execution time Memory
396669 2021-04-30T14:49:17 Z Sorting Training (IOI07_training) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

const long long N = 2000 + 3;
const long long M = 5000 + 3;

long long n, m;

vector<long long> adj[N];
vector<array<long long, 3>> e, e2;
vector<long long> arr, dp;
long long pos[N];

void dfs(long long u, long long p = -1){
    arr.push_back(u);
    pos[u] = (long long)arr.size() - 1;

    for(long long to: adj[u])
        if(to != p)
            dfs(to, u);
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> m;
    for(long long i = 0; i < m; ++i){
        long long a, b, c;
        cin >> a >> b >> c;
        if(!c){
            adj[a].push_back(b);
            adj[b].push_back(a);
        }
        else e.push_back({a, b, c});
    }

    dfs(1);

    for(long long i = 0; i < e.size(); ++i){
        auto [a, b, c] = e[i];
        long long new_a = pos[a];
        long long new_b = pos[b];
        e[i] = {min(new_a, new_b), max(new_a, new_b), c};
    }

    long long ans = 0;
    for(long long i = 0; i < e.size(); ++i){
        auto [a, b, c] = e[i];
        if((b - a) & 1) ans += c;
        else e2.push_back({a, b, c});
    }

    sort(e2.begin(), e2.end());
    
    for(auto [a, b, c]: e2)
        cout << a << " " << b << " " << c << endl;


    dp.resize(e2.size() + 1);
    dp[e2.size()] = 0;
    for(long long i = (long long)e2.size() - 1; i >= 0; --i){
        long long next_idx = lower_bound(e2.begin(), e2.end(), array{e2[i][1] + 1, 0, 0}) - e2.begin();
        next_idx = max(next_idx, i + 1);
        dp[i] = max(dp[i + 1], e2[i][2] + dp[next_idx]);
    }

    ans -= dp[0];
    for(long long i = 0; i < e2.size(); ++i)
        ans += e2[i][2];

    cout << ans << "\n";
}
/*
3 3
1 3 1
1 2 0
2 3 0
*/

Compilation message

training.cpp: In function 'int main()':
training.cpp:41:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(long long i = 0; i < e.size(); ++i){
      |                          ~~^~~~~~~~~~
training.cpp:49:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(long long i = 0; i < e.size(); ++i){
      |                          ~~^~~~~~~~~~
training.cpp:64:88: error: class template argument deduction failed:
   64 |         long long next_idx = lower_bound(e2.begin(), e2.end(), array{e2[i][1] + 1, 0, 0}) - e2.begin();
      |                                                                                        ^
training.cpp:64:88: error: no matching function for call to 'array(std::array<long long int, 3>::value_type, int, int)'
In file included from /usr/include/c++/9/tuple:39,
                 from /usr/include/c++/9/functional:54,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from training.cpp:1:
/usr/include/c++/9/array:244:5: note: candidate: 'template<class _Tp, class ... _Up> std::array(_Tp, _Up ...)-> std::array<typename std::enable_if<(is_same_v<_Tp, _Up> && ...), _Tp>::type, (1 + sizeof... (_Up))>'
  244 |     array(_Tp, _Up...)
      |     ^~~~~
/usr/include/c++/9/array:244:5: note:   template argument deduction/substitution failed:
/usr/include/c++/9/array: In substitution of 'template<class _Tp, class ... _Up> std::array(_Tp, _Up ...)-> std::array<typename std::enable_if<(is_same_v<_Tp, _Up> && ...), _Tp>::type, (1 + sizeof... (_Up))> [with _Tp = long long int; _Up = {int, int}]':
training.cpp:64:88:   required from here
/usr/include/c++/9/array:244:5: error: no type named 'type' in 'struct std::enable_if<false, long long int>'
training.cpp:70:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(long long i = 0; i < e2.size(); ++i)
      |                          ~~^~~~~~~~~~~