This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |