답안 #533257

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
533257 2022-03-05T08:06:46 Z rk42745417 철도 요금 (JOI16_ho_t3) C++17
100 / 100
151 ms 16236 KB
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const ll LINF = ll(4e18) + ll(2e15);
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
static int LamyIsCute = []() {
	EmiliaMyWife
	return 48763;
}();

signed main() {
	int n, m, q;
	cin >> n >> m >> q;
	vector<int> dis(n + 1, INF);
	vector<pair<int, int>> edges(m);
	vector<vector<pair<int, int>>> edge(n + 1);
	for(int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		edge[u].push_back({v, i});
		edge[v].push_back({u, i});
		edges[i] = {u, v};
	}
	
	queue<int> bfs;
	bfs.push(1);
	dis[1] = 0;
	while(!bfs.empty()) {
		int u = bfs.front();
		bfs.pop();
		for(const auto &[v, _] : edge[u])
			if(dis[v] > dis[u] + 1)
				dis[v] = dis[u] + 1, bfs.push(v);
	}

	vector<int> cnt(n + 1);
	for(int i = 2; i <= n; i++) {
		for(const auto &[v, _] : edge[i])
			if(dis[v] == dis[i] - 1)
				cnt[i]++;
	}

	vector<bool> has(n + 1), dele(m);
	int res = 0;
	while(q--) {
		int x;
		cin >> x;
		x--;
		dele[x] = true;
		auto [u, v] = edges[x];

		if(!has[v] && !has[u] && abs(dis[u] - dis[v]) == 1) {
			if(dis[u] > dis[v])
				swap(u, v);

			cnt[v]--;
			queue<int> que;
			if(cnt[v] == 0)
				que.push(v);

			while(!que.empty()) {
				int u = que.front();
				que.pop();
				has[u] = true;
				res++;

				for(const auto &[v, i] : edge[u]) {
					if(!dele[i] && dis[v] == dis[u] + 1) {
						cnt[v]--;
						if(cnt[v] == 0)
							que.push(v);
					}
				}
			}
		}

		cout << res << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 106 ms 11884 KB Output is correct
10 Correct 85 ms 11904 KB Output is correct
11 Correct 103 ms 11548 KB Output is correct
12 Correct 85 ms 11588 KB Output is correct
13 Correct 80 ms 11716 KB Output is correct
14 Correct 92 ms 11652 KB Output is correct
15 Correct 49 ms 8756 KB Output is correct
16 Correct 38 ms 7924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 95 ms 11800 KB Output is correct
2 Correct 92 ms 12380 KB Output is correct
3 Correct 62 ms 10544 KB Output is correct
4 Correct 81 ms 12060 KB Output is correct
5 Correct 94 ms 12168 KB Output is correct
6 Correct 86 ms 12192 KB Output is correct
7 Correct 46 ms 8420 KB Output is correct
8 Correct 37 ms 8376 KB Output is correct
9 Correct 30 ms 7960 KB Output is correct
10 Correct 27 ms 7880 KB Output is correct
11 Correct 132 ms 11972 KB Output is correct
12 Correct 107 ms 12988 KB Output is correct
13 Correct 95 ms 12772 KB Output is correct
14 Correct 93 ms 13768 KB Output is correct
15 Correct 112 ms 13092 KB Output is correct
16 Correct 87 ms 12732 KB Output is correct
17 Correct 119 ms 13140 KB Output is correct
18 Correct 65 ms 9668 KB Output is correct
19 Correct 140 ms 15820 KB Output is correct
20 Correct 103 ms 13232 KB Output is correct
21 Correct 51 ms 9024 KB Output is correct
22 Correct 56 ms 9056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 106 ms 11884 KB Output is correct
10 Correct 85 ms 11904 KB Output is correct
11 Correct 103 ms 11548 KB Output is correct
12 Correct 85 ms 11588 KB Output is correct
13 Correct 80 ms 11716 KB Output is correct
14 Correct 92 ms 11652 KB Output is correct
15 Correct 49 ms 8756 KB Output is correct
16 Correct 38 ms 7924 KB Output is correct
17 Correct 95 ms 11800 KB Output is correct
18 Correct 92 ms 12380 KB Output is correct
19 Correct 62 ms 10544 KB Output is correct
20 Correct 81 ms 12060 KB Output is correct
21 Correct 94 ms 12168 KB Output is correct
22 Correct 86 ms 12192 KB Output is correct
23 Correct 46 ms 8420 KB Output is correct
24 Correct 37 ms 8376 KB Output is correct
25 Correct 30 ms 7960 KB Output is correct
26 Correct 27 ms 7880 KB Output is correct
27 Correct 132 ms 11972 KB Output is correct
28 Correct 107 ms 12988 KB Output is correct
29 Correct 95 ms 12772 KB Output is correct
30 Correct 93 ms 13768 KB Output is correct
31 Correct 112 ms 13092 KB Output is correct
32 Correct 87 ms 12732 KB Output is correct
33 Correct 119 ms 13140 KB Output is correct
34 Correct 65 ms 9668 KB Output is correct
35 Correct 140 ms 15820 KB Output is correct
36 Correct 103 ms 13232 KB Output is correct
37 Correct 51 ms 9024 KB Output is correct
38 Correct 56 ms 9056 KB Output is correct
39 Correct 137 ms 16236 KB Output is correct
40 Correct 151 ms 16168 KB Output is correct
41 Correct 88 ms 12352 KB Output is correct
42 Correct 125 ms 15940 KB Output is correct
43 Correct 136 ms 15796 KB Output is correct
44 Correct 149 ms 15808 KB Output is correct
45 Correct 126 ms 15764 KB Output is correct
46 Correct 59 ms 10308 KB Output is correct
47 Correct 64 ms 9828 KB Output is correct
48 Correct 61 ms 9680 KB Output is correct
49 Correct 49 ms 8856 KB Output is correct
50 Correct 51 ms 8868 KB Output is correct
51 Correct 59 ms 9648 KB Output is correct
52 Correct 52 ms 9672 KB Output is correct
53 Correct 50 ms 8764 KB Output is correct
54 Correct 53 ms 8884 KB Output is correct