Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv)
- {
- int n, m;
- cin >> n >> m;
- vi g[1 << 11];
- for (int i = 0; i < m; ++i) {
- int u, v;
- cin >> u >> v;
- g[u].push_back(v), g[v].push_back(u);
- }
- vector<vi> dist(1 << 11, vi(1 << 11, INT_MAX / 2));
- for (int i = 1; i <= n; ++i) {
- vector<int> vis(1 << 11);
- queue<pii> q;
- q.push({i, 0});
- while (q.empty() == false) {
- auto [u, d] = q.front();
- q.pop();
- vis[u] = 1;
- dist[i][u] = d;
- for (auto v : g[u])
- if (vis[v] == 0)
- q.push({v, d + 1});
- }
- }
- int k;
- set<int> wlist;
- vi blist[1 << 11];
- cin >> k;
- vi p(k), d(k);
- for (int i = 0; i < k; ++i) {
- cin >> p[i] >> d[i];
- int u = p[i], di = d[i];
- for (int v = 1; v <= n; ++v) {
- if (dist[u][v] < di) {
- wlist.insert(v);
- } else if (dist[u][v] == di) {
- blist[u].push_back(v);
- }
- }
- }
- string ans = string(n, '1');
- for (auto x : wlist)
- ans[x - 1] = '0';
- bool succ = true;
- for (int i = 0; i < k && succ; ++i) {
- int u = p[i];
- bool hit = false;
- for (auto v : blist[u])
- if (ans[v - 1] == '1')
- hit = true;
- succ = succ && hit;
- }
- if (succ)
- cout << "Yes\n" << ans << '\n';
- else
- cout << "No\n";
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement