Submission #334044

# Submission time Handle Problem Language Result Execution time Memory
334044 2020-12-08T07:39:33 Z ronnith Klasika (COCI20_klasika) C++14
33 / 110
129 ms 1388 KB
#include <bits/stdc++.h>

typedef long long ll;
#define trav(a, b) for(auto a : b)
#define v vector
#define vl vector<ll>
#define mk make_pair
#define f first
#define s second

using namespace std;

vector<pair<int, int>> adj[2000];
int vis[2000];

int crr;

void ff(int x, int pr, bool flag){
	if(x == crr)flag = true;
	if(flag){
		vis[x] = 1;
	}
	trav(e, adj[x]){
		if(e.f != pr)ff(e.f, x, flag);
	}
}

int ans = 0;

void dfs(int x, int pr, int level){
	if(vis[x])
		ans = max(ans, level);
	trav(e, adj[x]){
		if(e.f != pr){
			dfs(e.f, x, level ^ e.s);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	int q;
	cin >> q;
	string x;
	int a, b, size = 1;
	while(q --){
		cin >> x >> a >> b;
		if(x == "Add"){
			adj[a - 1].push_back(mk(size, b));
			adj[size].push_back(mk(a - 1, b));
			size ++;
		} else {
			crr = b - 1;
			for(int i = 0;i < size;i ++)vis[i] = 0;
			ff(0, -1, false);
			ans = 0;
			dfs(a - 1, -1, 0);
			cout << ans << '\n';
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 8 ms 492 KB Output is correct
14 Correct 9 ms 492 KB Output is correct
15 Correct 9 ms 492 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 14 ms 492 KB Output is correct
19 Correct 14 ms 492 KB Output is correct
20 Correct 13 ms 492 KB Output is correct
21 Correct 8 ms 492 KB Output is correct
22 Correct 13 ms 492 KB Output is correct
23 Correct 13 ms 512 KB Output is correct
24 Correct 9 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 129 ms 1388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 8 ms 492 KB Output is correct
14 Correct 9 ms 492 KB Output is correct
15 Correct 9 ms 492 KB Output is correct
16 Correct 6 ms 620 KB Output is correct
17 Correct 9 ms 492 KB Output is correct
18 Correct 14 ms 492 KB Output is correct
19 Correct 14 ms 492 KB Output is correct
20 Correct 13 ms 492 KB Output is correct
21 Correct 8 ms 492 KB Output is correct
22 Correct 13 ms 492 KB Output is correct
23 Correct 13 ms 512 KB Output is correct
24 Correct 9 ms 492 KB Output is correct
25 Runtime error 129 ms 1388 KB Execution killed with signal 11 (could be triggered by violating memory limits)
26 Halted 0 ms 0 KB -