답안 #938242

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
938242 2024-03-05T03:33:09 Z Gromp15 Inside information (BOI21_servers) C++17
2.5 / 100
3500 ms 15668 KB
#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
const int INF = 1e9;
void test_case() {
	int n, q;
	cin >> n >> q;
	vector<vector<ar<int, 2>>> adj(n+1);
	vector<ar<int, 5>> queries;
	vector<int> ans(q);
	vector<bool> type(q);
	for (int i = 0, qidx = 0; i < n + q - 1; i++) {
		char c; cin >> c;
		int x, y;
		cin >> x;
		if (c != 'C') cin >> y;
		if (c == 'S') {
			adj[x].push_back({y, i});
			adj[y].push_back({x, i});
		}
		else {
			if (c == 'Q') {
				queries.push_back({0, x, y, qidx++, i});
			}
			else {
				queries.push_back({1, x, -1, qidx++, i});
			}
		}
	}
	for (auto [tp, x, y, ans_idx, time] : queries) {
		if (tp == 0) {
			vector<int> dist(n+1, -1);
			dist[x] = time;
			auto dfs = [&](auto&& s, int v) -> void {
				for (auto [u, w] : adj[v]) if (dist[v] >= w && ckmax(dist[u], w)) {
					s(s, u);
				}
			};
			dfs(dfs, x);
			type[ans_idx] = 1;
			ans[ans_idx] = bool(~dist[y]); // good if it's not -1
		}
		else {
			vector<int> dist(n+1, INF);
			dist[x] = -1;
			auto dfs = [&](auto&& s, int v) -> void {
				for (auto [u, w] : adj[v]) if (dist[v] <= w && ckmin(dist[u], w)) {
					s(s, u);
				}
			};
			for (auto [u, w] : adj[x]) if (w <= time) {
				dist[u] = w;
				dfs(dfs, u);
			}
			int cnt = 0;
			for (int i = 1; i <= n; i++) {
				cnt += dist[i] < INF;
			}
			ans[ans_idx] = cnt;
		}
	}
	for (int i = 0; i < q; i++) {
		if (type[i]) {
			cout << (ans[i] ? "yes":"no") << '\n';
		}
		else cout << ans[i] << '\n';
	}




}
int main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
//    cin >> t;
    while (t--) test_case();
}

# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4632 KB Output is correct
2 Correct 51 ms 5044 KB Output is correct
3 Correct 249 ms 5468 KB Output is correct
4 Correct 52 ms 5176 KB Output is correct
5 Correct 48 ms 5200 KB Output is correct
6 Correct 1045 ms 5332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 4632 KB Output is correct
2 Correct 51 ms 5044 KB Output is correct
3 Correct 249 ms 5468 KB Output is correct
4 Correct 52 ms 5176 KB Output is correct
5 Correct 48 ms 5200 KB Output is correct
6 Correct 1045 ms 5332 KB Output is correct
7 Incorrect 22 ms 5328 KB Extra information in the output file
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 4584 KB Output is correct
2 Execution timed out 3550 ms 13908 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 4584 KB Output is correct
2 Execution timed out 3550 ms 13908 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 5328 KB Output is correct
2 Correct 775 ms 14048 KB Output is correct
3 Correct 793 ms 13920 KB Output is correct
4 Execution timed out 3533 ms 15108 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 5328 KB Output is correct
2 Correct 775 ms 14048 KB Output is correct
3 Correct 793 ms 13920 KB Output is correct
4 Execution timed out 3533 ms 15108 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5068 KB Output is correct
2 Execution timed out 3570 ms 14540 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 5068 KB Output is correct
2 Execution timed out 3570 ms 14540 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5328 KB Output is correct
2 Correct 754 ms 14048 KB Output is correct
3 Correct 775 ms 14044 KB Output is correct
4 Execution timed out 3543 ms 15668 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 5328 KB Output is correct
2 Correct 754 ms 14048 KB Output is correct
3 Correct 775 ms 14044 KB Output is correct
4 Execution timed out 3543 ms 15668 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 4548 KB Output is correct
2 Correct 51 ms 5164 KB Output is correct
3 Correct 237 ms 5276 KB Output is correct
4 Correct 48 ms 5168 KB Output is correct
5 Correct 55 ms 5348 KB Output is correct
6 Correct 1047 ms 5332 KB Output is correct
7 Correct 27 ms 4548 KB Output is correct
8 Execution timed out 3522 ms 13908 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 21 ms 4548 KB Output is correct
2 Correct 51 ms 5164 KB Output is correct
3 Correct 237 ms 5276 KB Output is correct
4 Correct 48 ms 5168 KB Output is correct
5 Correct 55 ms 5348 KB Output is correct
6 Correct 1047 ms 5332 KB Output is correct
7 Correct 27 ms 4548 KB Output is correct
8 Execution timed out 3522 ms 13908 KB Time limit exceeded
9 Halted 0 ms 0 KB -