Submission #976295

# Submission time Handle Problem Language Result Execution time Memory
976295 2024-05-06T11:49:27 Z saayan007 Factories (JOI14_factories) C++17
0 / 100
8000 ms 63964 KB
#include "factories.h"
#include "bits/stdc++.h"
using namespace std;

const char nl = '\n';

using ll = long long;
#warning checkconstanst as per subtask
const int mxN = 5e5L + 10;

vector<pair<int, ll>> adj[mxN];
ll dist[mxN];
queue<int> q;
int n;
ll res = -1;

/* void Init(int N, int A[], int B[], int D[]) { */
void Init(signed N, signed A[], signed B[], signed D[]) {
    n = N;
    for(int i = 0; i < N - 1; ++i) {
        adj[A[i]].emplace_back(B[i], ll(D[i]));
        adj[B[i]].emplace_back(A[i], ll(D[i]));
    }
    for(int i = 0; i < N; ++i) {
        dist[i] = -1;
    }
}

void dfs(int x, int p) {
    for(auto U : adj[x]) {
        int y = U.first;
        ll w = U.second;
        if(y == p) continue;
        dist[y] = dist[x] + w;
        dfs(y, x);
    }
}

long long Query(signed S, signed X[], signed T, signed Y[]) {
    res = -1;
    for(int i = 0; i < S; ++i) {
        dist[X[i]] = 0;
        dfs(X[i], -1);
        for(int j = 0; j < T; ++j) {
            if(dist[Y[j]] != -1 && (res > dist[Y[j]] || res == -1)) res = dist[Y[j]];
        }
    }
    return res;
}

Compilation message

factories.cpp:8:2: warning: #warning checkconstanst as per subtask [-Wcpp]
    8 | #warning checkconstanst as per subtask
      |  ^~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 81 ms 31324 KB Output is correct
2 Execution timed out 8098 ms 35412 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 13 ms 31064 KB Output is correct
2 Execution timed out 8032 ms 63964 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 81 ms 31324 KB Output is correct
2 Execution timed out 8098 ms 35412 KB Time limit exceeded
3 Halted 0 ms 0 KB -