답안 #976274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
976274 2024-05-06T11:27:40 Z saayan007 공장들 (JOI14_factories) C++17
0 / 100
17 ms 31068 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];
ll dist[mxN];
queue<int> q;
int n;

/* void Init(int N, int A[], int B[], int D[]) { */
void Init(int32_t N, int32_t A[], int32_t B[], int32_t 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) {
        dist[i] = -1;
    }
}

/* long long Query(int S, int X[], int T, int Y[]) { */
long long Query(int32_t S, int32_t X[], int32_t T, int32_t Y[]) {
    /* 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 = 1e18;
    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;

    return res;
}

Compilation message

factories.cpp: In function 'void Init(int32_t, int32_t*, int32_t*, int32_t*)':
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:32:5: note: in expansion of macro 'rep'
   32 |     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:36:5: note: in expansion of macro 'rep'
   36 |     rep(i, 0, N - 1) {
      |     ^~~
factories.cpp: In function 'long long int Query(int32_t, int32_t*, int32_t, int32_t*)':
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:44:5: note: in expansion of macro 'rep'
   44 |     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:61:5: note: in expansion of macro 'rep'
   61 |     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:65:5: note: in expansion of macro 'rep'
   65 |     rep(i, 0, n - 1) dist[i] = -1;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 31068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 17 ms 31068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 16 ms 31068 KB Output isn't correct
2 Halted 0 ms 0 KB -