Submission #888501

# Submission time Handle Problem Language Result Execution time Memory
888501 2023-12-17T14:56:05 Z fanwen Nestabilnost (COI23_nestabilnost) C++17
0 / 100
94 ms 20128 KB
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define ll long long
#define file(name)                  \
    if(fopen(name".inp", "r"))      \
        freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout); 

const int MAX = 3e5 + 5;

int n, a[MAX], f[MAX];

vector <int> adj[MAX];

namespace sub1 {

	bool check() {
		return (int) adj[1].size() == n - 1;
	}

	long long ans = 0;

	int g[MAX];

	long long calc(int k) {
		long long ans = f[k];
		for (int i = 1; i <= n; ++i) {
			if(i == 1 || (a[i] == (a[1] + 1) % k && a[i] < k)) {
				continue;
			}

			ans += g[a[i] + 1];
		}
		return ans;
	}
	
	void solve() {
		for (int i = n; i >= 1; --i) g[i] = (i == n ? f[i] : min(g[i + 1], f[i]));
		for (int i = 1; i <= n; ++i) ans += g[a[i] + 1];
		int id = n;
		for (int i = n - 1; i > a[1] + 1; --i) {
			if(g[i] < g[i + 1]) id = i;
		}
		ans = min(ans, calc(id));
		ans = min(ans, calc(a[1] + 1));
		cout << ans; exit(0);
	}
}

void you_make_it(void) {
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    for (int i = 1; i <= n; ++i) cin >> f[i];
    for (int i = 1; i < n; ++i) {
    	int u, v; cin >> u >> v;
    	adj[u].push_back(v);
    	adj[v].push_back(u);
    }
    if(sub1::check()) sub1::solve();
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    file("nestabilnost");
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.

Compilation message

code1.cpp: In function 'int main()':
code1.cpp:10:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
code1.cpp:71:5: note: in expansion of macro 'file'
   71 |     file("nestabilnost");
      |     ^~~~
code1.cpp:10:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |         freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout);
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
code1.cpp:71:5: note: in expansion of macro 'file'
   71 |     file("nestabilnost");
      |     ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 20128 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 10588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10840 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 10840 KB Output isn't correct
2 Halted 0 ms 0 KB -