Submission #464058

# Submission time Handle Problem Language Result Execution time Memory
464058 2021-08-12T10:21:02 Z AmShZ Inside information (BOI21_servers) C++11
0 / 100
3500 ms 22928 KB
//khodaya khodet komak kon
# include <bits/stdc++.h>

using namespace std;

typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;

# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define lc                                              id << 1
# define rc                                              id << 1 | 1
# define fast_io                                         ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);

ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}

const int xn = 3e5 + 10;
const int xm = - 20 + 10;
const int sq = 320;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const ld eps = 1e-15;
const int mod = 1e9 + 7;//998244353;
const int base = 257;

int n, k, a[xn], ans;
vector <pii> adj[xn];
vector <int> vec;
bool fl[xn];

void DFS(int v, int p = - 1){
	if (p == - 1)
		fl[v] = true, a[v] = 0;
	else
		fl[v] = (fl[p] && a[p] < a[v]);
	vec.push_back(v);
	for (pii u : adj[v])
		if (u.A != p)
			a[u.A] = u.B, DFS(u.A, v);
}

int main(){
	fast_io;

	cin >> n >> k;
	for (int i = 1; i < n + k; ++ i){
		char c;
		int v, u;
		cin >> c;
		if (c == 'S'){
			cin >> v >> u;
			adj[v].push_back({u, i});
			adj[u].push_back({v, i});
		}
		else if (c == 'Q'){
			cin >> u >> v;
			vec.clear();
			DFS(v);
			bool flag = false;
			for (int z : vec)
				flag |= (z == u);
			if (fl[u] && a[u] <= i && flag)
				cout << "yes" << endl;
			else
				cout << "no" << endl;
		}
		else{
			cin >> v;
			vec.clear();
			DFS(v);
			ans = 0;
			for (int u : vec)
				ans += (fl[u] && a[u] <= i);
			cout << ans << endl;
		}
	}

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 53 ms 7620 KB Output is correct
2 Correct 899 ms 9548 KB Output is correct
3 Correct 1771 ms 9380 KB Output is correct
4 Correct 113 ms 9432 KB Output is correct
5 Execution timed out 3557 ms 8516 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 7620 KB Output is correct
2 Correct 899 ms 9548 KB Output is correct
3 Correct 1771 ms 9380 KB Output is correct
4 Correct 113 ms 9432 KB Output is correct
5 Execution timed out 3557 ms 8516 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 7704 KB Output is correct
2 Execution timed out 3561 ms 9308 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 62 ms 7704 KB Output is correct
2 Execution timed out 3561 ms 9308 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7800 KB Output is correct
2 Correct 299 ms 22260 KB Output is correct
3 Correct 252 ms 22928 KB Output is correct
4 Execution timed out 3549 ms 10612 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 56 ms 7800 KB Output is correct
2 Correct 299 ms 22260 KB Output is correct
3 Correct 252 ms 22928 KB Output is correct
4 Execution timed out 3549 ms 10612 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 54 ms 7672 KB Output is correct
2 Execution timed out 3587 ms 12600 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 7672 KB Output is correct
2 Execution timed out 3587 ms 12600 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 7712 KB Output is correct
2 Correct 280 ms 22760 KB Output is correct
3 Correct 248 ms 22908 KB Output is correct
4 Execution timed out 3544 ms 10688 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 53 ms 7712 KB Output is correct
2 Correct 280 ms 22760 KB Output is correct
3 Correct 248 ms 22908 KB Output is correct
4 Execution timed out 3544 ms 10688 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 7692 KB Output is correct
2 Correct 910 ms 9292 KB Output is correct
3 Correct 1748 ms 9580 KB Output is correct
4 Correct 113 ms 9328 KB Output is correct
5 Execution timed out 3564 ms 8732 KB Time limit exceeded
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 7692 KB Output is correct
2 Correct 910 ms 9292 KB Output is correct
3 Correct 1748 ms 9580 KB Output is correct
4 Correct 113 ms 9328 KB Output is correct
5 Execution timed out 3564 ms 8732 KB Time limit exceeded
6 Halted 0 ms 0 KB -