Submission #976270

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

#warning using32bitint
#define int long long
typedef long long ll;
typedef pair<int, int> pi;
#define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
#define repd(i, a, b) for(int (i) = (a); i >= (b); --i)

#define em emplace
#define eb emplace_back

#define fr first
#define sc second
#define mp make_pair

const char nl = '\n';

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

vector<pair<int, ll>> adj[mxN];
bool spec[mxN];
ll dist[mxN];
queue<int> q;
int n;

/* void Init(int N, int A[], int B[], int D[]) { */
void Init(signed N, signed A[], signed B[], signed D[]) {
    n = N;
    rep(i, 0, N - 2) {
        adj[A[i]].eb(B[i], D[i]);
        adj[B[i]].eb(A[i], D[i]);
    }
    rep(i, 0, N - 1) {
        spec[i] = 0;
        dist[i] = -1;
    }
}

/* long long Query(int S, int X[], int T, int Y[]) { */
long long Query(signed S, signed X[], signed T, signed Y[]) {
    rep(i, 0, S - 1) spec[X[i]] = 1;
    /* for(int x : X) spec[x] = 1; */

    /* for(int y : Y) { */
    rep(i, 0, T - 1) {
        dist[Y[i]] = 0;
        q.push(Y[i]);
    }
    
    while(!q.empty()) {
        int a = q.front();
        q.pop();
        for(auto tmp : adj[a]) {
            int b = tmp.fr; ll w = tmp.sc;
            if(dist[b] != -1) continue;
            dist[b] = dist[a] + w;
            q.push(b);
        }
    }

    ll res = mxN;
    rep(i, 0, S - 1) {
        if(dist[X[i]] != -1 && dist[X[i]] < res) res = dist[X[i]];
    }

    rep(i, 0, n - 1) dist[i] = -1;
    rep(i, 0, S - 1) spec[X[i]] = 0;

    return res;
}

Compilation message

factories.cpp:5:2: warning: #warning using32bitint [-Wcpp]
    5 | #warning using32bitint
      |  ^~~~~~~
factories.cpp:21:2: warning: #warning checkconstanst as per subtask [-Wcpp]
   21 | #warning checkconstanst as per subtask
      |  ^~~~~~~
factories.cpp: In function 'void Init(int, int*, int*, int*)':
factories.cpp:9:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
factories.cpp:33:5: note: in expansion of macro 'rep'
   33 |     rep(i, 0, N - 2) {
      |     ^~~
factories.cpp:9:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
factories.cpp:37:5: note: in expansion of macro 'rep'
   37 |     rep(i, 0, N - 1) {
      |     ^~~
factories.cpp: In function 'long long int Query(int, int*, int, int*)':
factories.cpp:9:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
factories.cpp:45:5: note: in expansion of macro 'rep'
   45 |     rep(i, 0, S - 1) spec[X[i]] = 1;
      |     ^~~
factories.cpp:9:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
factories.cpp:49:5: note: in expansion of macro 'rep'
   49 |     rep(i, 0, T - 1) {
      |     ^~~
factories.cpp:9:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
factories.cpp:66:5: note: in expansion of macro 'rep'
   66 |     rep(i, 0, S - 1) {
      |     ^~~
factories.cpp:9:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
factories.cpp:70:5: note: in expansion of macro 'rep'
   70 |     rep(i, 0, n - 1) dist[i] = -1;
      |     ^~~
factories.cpp:9:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    9 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
factories.cpp:71:5: note: in expansion of macro 'rep'
   71 |     rep(i, 0, S - 1) spec[X[i]] = 0;
      |     ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 35164 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 33116 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 35164 KB Output isn't correct
2 Halted 0 ms 0 KB -