Submission #882285

# Submission time Handle Problem Language Result Execution time Memory
882285 2023-12-03T00:02:32 Z noompty Factories (JOI14_factories) C++17
15 / 100
8000 ms 73044 KB
#include <iostream>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
#include <cmath>
#include <array>
#include <random>
#include <string>
#include <cassert>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include "factories.h"
using namespace std;
 
#define ll long long
#define f first
#define s second
 
void __print(int x) { cerr << x; }
void __print(long x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
 
template<typename A> void __print(const A &x);
template<typename A, typename B> void __print(const pair<A, B> &p);
template<typename... A> void __print(const tuple<A...> &t);
template<typename T> void __print(stack<T> s);
template<typename T> void __print(queue<T> q);
template<typename T, typename... U> void __print(priority_queue<T, U...> q);
 
template<typename A> void __print(const A &x) {
    bool first = true;
    cerr << '{';
    for (const auto &i : x) {
        cerr << (first ? "" : ","), __print(i);
        first = false;
    }
    cerr << '}';
}
 
template<typename A, typename B> void __print(const pair<A, B> &p) {
    cerr << '(';
    __print(p.f);
    cerr << ',';
    __print(p.s);
    cerr << ')';
}
 
template<typename... A> void __print(const tuple<A...> &t) {
    bool first = true;
    cerr << '(';
    apply([&first] (const auto &...args) { ((cerr << (first ? "" : ","), __print(args), first = false), ...); }, t);
    cerr << ')';
}
 
template<typename T> void __print(stack<T> s) {
    vector<T> debugVector;
    while (!s.empty()) {
        T t = s.top();
        debugVector.push_back(t);
        s.pop();
    }
    reverse(debugVector.begin(), debugVector.end());
    __print(debugVector);
}
 
template<typename T> void __print(queue<T> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.front();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
 
template<typename T, typename... U> void __print(priority_queue<T, U...> q) {
    vector<T> debugVector;
    while (!q.empty()) {
        T t = q.top();
        debugVector.push_back(t);
        q.pop();
    }
    __print(debugVector);
}
 
void _print() { cerr << "]\n"; }
 
template <typename Head, typename... Tail> void _print(const Head &H, const Tail &...T) {
    __print(H);
    if (sizeof...(T)) cerr << ", ";
    _print(T...);
}
 
#ifdef DEBUG
	#define D(...) cerr << "Line: " << __LINE__ << " [" << #__VA_ARGS__ << "] = ["; _print(__VA_ARGS__)
#else
	#define D(...)
#endif

int n;
ll ans;
vector<pair<int, int>> adj[500005];
bool u[500005], v[500005];

pair<ll, ll> dfs(int curr, int par) {
    ll mnu = 1e16, mnv = 1e16;
    for (auto [i, d] : adj[curr]) {
        if (i == par) continue;
        pair<ll, ll> nxt = dfs(i, curr);
        mnu = min(mnu, nxt.f + d);
        mnv = min(mnv, nxt.s + d);
    }
    if (u[curr]) mnu = 0;
    if (v[curr]) mnv = 0;
    ans = min(ans, mnu + mnv);
    return {mnu, mnv};
}

void Init(int N, int A[], int B[], int D[]) {
    n = N;
    for (int i = 0; i < n - 1; i++) {
        adj[A[i]].push_back({B[i], D[i]});
        adj[B[i]].push_back({A[i], D[i]});
    }
}

ll Query(int S, int X[], int T, int Y[]) {
    for (int i = 0; i < S; i++) {
        u[X[i]] = true;
    }
    for (int i = 0; i < T; i++) {
        v[Y[i]] = true;
    }
    ans = 1e16;
    dfs(0, -1);
    for (int i = 0; i < S; i++) {
        u[X[i]] = false;
    }
    for (int i = 0; i < T; i++) {
        v[Y[i]] = false;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 11 ms 29276 KB Output is correct
2 Correct 508 ms 42728 KB Output is correct
3 Correct 583 ms 42980 KB Output is correct
4 Correct 584 ms 42936 KB Output is correct
5 Correct 595 ms 43232 KB Output is correct
6 Correct 275 ms 42832 KB Output is correct
7 Correct 595 ms 42956 KB Output is correct
8 Correct 551 ms 42952 KB Output is correct
9 Correct 626 ms 43220 KB Output is correct
10 Correct 281 ms 42976 KB Output is correct
11 Correct 603 ms 42952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 29016 KB Output is correct
2 Execution timed out 8023 ms 73044 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 29276 KB Output is correct
2 Correct 508 ms 42728 KB Output is correct
3 Correct 583 ms 42980 KB Output is correct
4 Correct 584 ms 42936 KB Output is correct
5 Correct 595 ms 43232 KB Output is correct
6 Correct 275 ms 42832 KB Output is correct
7 Correct 595 ms 42956 KB Output is correct
8 Correct 551 ms 42952 KB Output is correct
9 Correct 626 ms 43220 KB Output is correct
10 Correct 281 ms 42976 KB Output is correct
11 Correct 603 ms 42952 KB Output is correct
12 Correct 11 ms 29016 KB Output is correct
13 Execution timed out 8023 ms 73044 KB Time limit exceeded
14 Halted 0 ms 0 KB -