답안 #1110216

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110216 2024-11-09T02:40:06 Z vjudge1 Board Game (JOI24_boardgame) C++17
3 / 100
22 ms 4884 KB
#include <bits/stdc++.h>
#define Y8o "Board Game"
#define maxn (int) 5e4 + 5
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)

//#define f first
//#define s second

using namespace std;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
    return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
    if(fopen(Y8o".inp", "r"))
    {
        freopen(Y8o".inp", "r", stdin);
//        freopen(Y8o".out", "w", stdout);
    }
}
void ctime() {
    cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}

const int INF = 1e9;

int n, m, k;
vector<int> o[maxn];
int a[maxn], st[maxn];

namespace sub1 {

    int dp[maxn];

    void dij() {
        fi(i, 1, n) dp[i] = INF;
        dp[st[1]] = 0;

        priority_queue<pii> q;
        q.push({ -dp[st[1]], st[1] });

        while(q.size()) {
            int val = -q.top().first, u = q.top().second;
            q.pop();
            if(dp[u] > val) continue;

            for(int v : o[u]) {
                if(dp[v] > dp[u] + 1) {
                    dp[v] = dp[u] + 1;
                    q.push({ -dp[v], v });
                }
            }
        }
    }

    void solve() {
        dij();
        fi(i, 1, n) cout << dp[i] << '\n';
    }

}
void solve() {
    cin >> n >> m >> k;
    fi(i, 1, m) {
        int u, v; cin >> u >> v;
        o[u].push_back(v), o[v].push_back(u);
    }
    fi(i, 1, n) {
        char x; cin >> x;
        a[i] = x - '0';
    }
    fi(i, 1, k) cin >> st[i];

    if(*max_element(a + 1, a + n + 1) == 0) return sub1::solve(), void();
}


int main() {
    iof();

    int nTest = 1;
//    cin >> nTest;

    while(nTest --) {
        solve();
    }

    ctime();
    return 0;
}

Compilation message

Main.cpp: In function 'void iof()':
Main.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   27 |         freopen(Y8o".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1616 KB Output is correct
2 Correct 15 ms 3560 KB Output is correct
3 Correct 22 ms 4884 KB Output is correct
4 Correct 18 ms 4464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1872 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 3972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 13 ms 3972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 1616 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 1616 KB Output is correct
2 Correct 15 ms 3560 KB Output is correct
3 Correct 22 ms 4884 KB Output is correct
4 Correct 18 ms 4464 KB Output is correct
5 Incorrect 2 ms 1616 KB Output isn't correct
6 Halted 0 ms 0 KB -