Submission #332558

# Submission time Handle Problem Language Result Execution time Memory
332558 2020-12-02T21:29:19 Z souvenir_vayne Sjekira (COCI20_sjekira) C++14
0 / 110
1000 ms 2924 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <chrono>
#define pb push_back
#define INF 0x3f3f3f3f
//#define LINF 0x3f3f3f3f3f3f3f3f
//#define endl '\n'
#define ll long long
#define f first
#define int long long
#define fin cin
#define fout cout
#define s second
#define FAST cin.tie(0), cout.tie(0), ios::sync_with_stdio(0)
#define debug(x) cout << "DEBUG " << x << endl
#define debug2(x, y) cout << "DEBUG " << x << " " << y << endl
#define debug3(x, y, z) cout << "DEBUG " << x << " " << y << " " << z<< endl
#define debug4(x, y, z, o) cout << "DEBUG " << x << " " << y << " " << z<< " " << o << endl
#define all(x) x.begin(), x.end()
#define left vadia
#define lb lower_bound
#define right puta
using namespace std;
using namespace __gnu_pbds;
void setIO(string s) {
  ios_base::sync_with_stdio(0); cin.tie(0);
  freopen((s+".in").c_str(),"r",stdin);
  freopen((s+".out").c_str(),"w",stdout);
}
typedef pair<ll, ll> pii;
typedef vector<vector<char>> mat;
typedef pair<int, string> pis;
const ll mod = 1e9+7;
typedef vector<int> vi;
typedef pair<int, pair<int, int>> piii;

const int MAXN = 1e5+5;

int p[MAXN];
struct aux {
    int a = 0, b = 0, used = 0;
    bool operator<(aux x) {
        if(used != x.used)
            return used < x.used;
        return max(p[a], p[b]) < max(p[x.a], p[x.b]);
    }
};

int32_t main() {

    int n;
    cin >> n;

    for(int i = 1; i <= n; i++)
        cin >> p[i];

    vector<aux> e(n-1);
    for(int i = 0; i < n-1; i++)
        cin >> e[i].a >> e[i].b;

    int ans = 0;
    while(true) {
        sort(all(e));
        if(e[0].used) break;
        ans += p[e[0].a] + p[e[0].b];
        p[e[0].a] = p[e[0].b] = max(p[e[0].a], p[e[0].b]);
        e[0].used = 1;
    }

    cout << ans << endl;



}

Compilation message

sjekira.cpp: In function 'void setIO(std::string)':
sjekira.cpp:27:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   27 |   freopen((s+".in").c_str(),"r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sjekira.cpp:28:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |   freopen((s+".out").c_str(),"w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1089 ms 2924 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 1 ms 364 KB Output isn't correct
4 Halted 0 ms 0 KB -