Submission #365322

# Submission time Handle Problem Language Result Execution time Memory
365322 2021-02-11T12:53:59 Z GioChkhaidze None (JOI16_ho_t3) C++14
100 / 100
218 ms 26092 KB
#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]) {
		++ans;
		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] && !ed[x]) {
			lazy(b[x], x);
		}
 
		cout << ans << "\n";
	}
}

Compilation message

2016_ho_t3.cpp: In function 'void lazy(int, int)':
2016_ho_t3.cpp:22: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]
   22 |   for (int i = 0; i < g[x].size(); ++i) {
      |                   ~~^~~~~~~~~~~~~
2016_ho_t3.cpp: At global scope:
2016_ho_t3.cpp:30:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   30 | main () {
      |       ^
2016_ho_t3.cpp: In function 'int main()':
2016_ho_t3.cpp:49: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]
   49 |   for (int i = 0; i < v[x].size(); ++i) {
      |                   ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 8 ms 9964 KB Output is correct
4 Correct 7 ms 9836 KB Output is correct
5 Correct 7 ms 9836 KB Output is correct
6 Correct 7 ms 9836 KB Output is correct
7 Correct 8 ms 9708 KB Output is correct
8 Correct 7 ms 9708 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 8 ms 9964 KB Output is correct
4 Correct 7 ms 9836 KB Output is correct
5 Correct 7 ms 9836 KB Output is correct
6 Correct 7 ms 9836 KB Output is correct
7 Correct 8 ms 9708 KB Output is correct
8 Correct 7 ms 9708 KB Output is correct
9 Correct 141 ms 20716 KB Output is correct
10 Correct 132 ms 20716 KB Output is correct
11 Correct 112 ms 20588 KB Output is correct
12 Correct 113 ms 20844 KB Output is correct
13 Correct 126 ms 20988 KB Output is correct
14 Correct 130 ms 21100 KB Output is correct
15 Correct 84 ms 20844 KB Output is correct
16 Correct 66 ms 17772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 145 ms 20844 KB Output is correct
2 Correct 150 ms 20716 KB Output is correct
3 Correct 78 ms 18272 KB Output is correct
4 Correct 130 ms 20716 KB Output is correct
5 Correct 123 ms 21228 KB Output is correct
6 Correct 137 ms 21228 KB Output is correct
7 Correct 70 ms 17772 KB Output is correct
8 Correct 62 ms 17772 KB Output is correct
9 Correct 40 ms 15708 KB Output is correct
10 Correct 39 ms 16224 KB Output is correct
11 Correct 146 ms 20972 KB Output is correct
12 Correct 142 ms 23020 KB Output is correct
13 Correct 147 ms 22636 KB Output is correct
14 Correct 158 ms 23916 KB Output is correct
15 Correct 161 ms 23404 KB Output is correct
16 Correct 147 ms 23148 KB Output is correct
17 Correct 157 ms 25544 KB Output is correct
18 Correct 112 ms 23276 KB Output is correct
19 Correct 201 ms 25836 KB Output is correct
20 Correct 153 ms 25580 KB Output is correct
21 Correct 102 ms 21100 KB Output is correct
22 Correct 102 ms 21100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9708 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 8 ms 9964 KB Output is correct
4 Correct 7 ms 9836 KB Output is correct
5 Correct 7 ms 9836 KB Output is correct
6 Correct 7 ms 9836 KB Output is correct
7 Correct 8 ms 9708 KB Output is correct
8 Correct 7 ms 9708 KB Output is correct
9 Correct 141 ms 20716 KB Output is correct
10 Correct 132 ms 20716 KB Output is correct
11 Correct 112 ms 20588 KB Output is correct
12 Correct 113 ms 20844 KB Output is correct
13 Correct 126 ms 20988 KB Output is correct
14 Correct 130 ms 21100 KB Output is correct
15 Correct 84 ms 20844 KB Output is correct
16 Correct 66 ms 17772 KB Output is correct
17 Correct 145 ms 20844 KB Output is correct
18 Correct 150 ms 20716 KB Output is correct
19 Correct 78 ms 18272 KB Output is correct
20 Correct 130 ms 20716 KB Output is correct
21 Correct 123 ms 21228 KB Output is correct
22 Correct 137 ms 21228 KB Output is correct
23 Correct 70 ms 17772 KB Output is correct
24 Correct 62 ms 17772 KB Output is correct
25 Correct 40 ms 15708 KB Output is correct
26 Correct 39 ms 16224 KB Output is correct
27 Correct 146 ms 20972 KB Output is correct
28 Correct 142 ms 23020 KB Output is correct
29 Correct 147 ms 22636 KB Output is correct
30 Correct 158 ms 23916 KB Output is correct
31 Correct 161 ms 23404 KB Output is correct
32 Correct 147 ms 23148 KB Output is correct
33 Correct 157 ms 25544 KB Output is correct
34 Correct 112 ms 23276 KB Output is correct
35 Correct 201 ms 25836 KB Output is correct
36 Correct 153 ms 25580 KB Output is correct
37 Correct 102 ms 21100 KB Output is correct
38 Correct 102 ms 21100 KB Output is correct
39 Correct 218 ms 25580 KB Output is correct
40 Correct 201 ms 25720 KB Output is correct
41 Correct 106 ms 21216 KB Output is correct
42 Correct 181 ms 25748 KB Output is correct
43 Correct 166 ms 25836 KB Output is correct
44 Correct 160 ms 26092 KB Output is correct
45 Correct 180 ms 25964 KB Output is correct
46 Correct 98 ms 22380 KB Output is correct
47 Correct 83 ms 20204 KB Output is correct
48 Correct 86 ms 20204 KB Output is correct
49 Correct 65 ms 17628 KB Output is correct
50 Correct 69 ms 17888 KB Output is correct
51 Correct 71 ms 18268 KB Output is correct
52 Correct 72 ms 18528 KB Output is correct
53 Correct 60 ms 17500 KB Output is correct
54 Correct 83 ms 17888 KB Output is correct