Submission #1017721

# Submission time Handle Problem Language Result Execution time Memory
1017721 2024-07-09T09:39:30 Z MohamedFaresNebili September (APIO24_september) C++17
0 / 100
1 ms 3420 KB
#include <bits/stdc++.h>

		using namespace std;

		vector<int> adj[100005];
		int act[100005], rem[100005];
		bool leaf[100005];

		int solve(int N, int M, vector<int> F, vector<vector<int>> S) {
			for(int l = 0; l < N; l++) 
				adj[l].clear(), act[l] = leaf[l] = 0;
			for(int l = 1; l < N; l++) 
				adj[F[l]].push_back(l);
			for(int l = 0; l < N; l++) {
				if(adj[l].size() > 0) act[l] = (int)adj[l].size();
				else leaf[l] = 1;
			}

			int res = 0, cur = 0;
			for(int l = 0; l < N - 1; l++) {
				int U = S[0][l]; 
				if(leaf[U]) {
					while(F[U] != 0) {
						act[F[U]]--;
						if(act[F[U]] == 0) {
							leaf[F[U]] = 1;
							if(rem[F[U]]) {
								cur--; U = F[U];
							}
						}
						break;
					}
					
					if(cur == 0) ++res;
				}
				else rem[U] = 1, cur++;
			}

			return res;
		}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 3420 KB Output isn't correct
2 Halted 0 ms 0 KB -