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 pb push_back
#define F first
#define S second
using namespace std;
const int N = 2e5 + 5;
int n, m, q, ans;
int in[N], d[N], a[N], b[N];
bool act[N], ed[N], used[N];
vector < pair < int , int > > v[N], g[N];
queue < int > qr;
void lazy(int x, int idx) {
--in[x];
ed[idx] = true;
if (!in[x] && !used[x]) {
++ans;
used[x] = true;
for (int i = 0; i < g[x].size(); ++i) {
int to = g[x][i].F, id = g[x][i].S;
if (ed[id]) continue;
lazy(to, id);
}
}
}
main () {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> m >> q;
for (int i = 1; i <= m; ++i) {
cin >> a[i] >> b[i];
v[a[i]].pb({b[i], i});
v[b[i]].pb({a[i], i});
}
for (int i = 2; i <= n; ++i) {
d[i] = 1e9;
}
qr.push(1);
while (!qr.empty()) {
int x = qr.front();
qr.pop();
for (int i = 0; i < v[x].size(); ++i) {
int to = v[x][i].F, id = v[x][i].S;
if (d[x] + 1 < d[to]) {
d[to] = d[x] + 1;
qr.push(to);
}
if (d[x] + 1 == d[to]) {
g[x].pb({to, id});
act[id] = true;
++in[to];
}
}
}
for (int i = 1; i <= m; ++i) {
if (d[a[i]] > d[b[i]]) swap(a[i], b[i]);
}
for (int i = 1; i <= q; ++i) {
int x;
cin >> x;
if (act[x]) {
lazy(b[x], x);
}
cout << ans << "\n";
}
}
Compilation message (stderr)
2016_ho_t3.cpp: In function 'void lazy(int, int)':
2016_ho_t3.cpp:23:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < g[x].size(); ++i) {
| ~~^~~~~~~~~~~~~
2016_ho_t3.cpp: At global scope:
2016_ho_t3.cpp:31:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
31 | main () {
| ^
2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:50:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 0; i < v[x].size(); ++i) {
| ~~^~~~~~~~~~~~~
# | 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... |