이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
using namespace std;
// using namespace __gnu_pbds;
#define fi first
#define se second
#define REP(i, n) for (auto i = 0; i < (n); ++i)
#define FOR(i, a, b) for (auto i = (a); i <= (b); ++i)
#define FORD(i, a, b) for (auto i = (a); i >= (b); --i)
#define FORE(i, a, b) for (auto i = (a); i < (b); ++i)
#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define left ___left
#define right ___right
#define __builtin_popcount __builtin_popcountll
int solve(int N, int M, std::vector<int> F, std::vector<std::vector<int>> S) {
int ans = 0, res = 0;
vector <vector <int>> adj(N);
for (int i = 1; i < N; ++i) {
adj[F[i]].emplace_back(i);
}
vector <int> d(N);
int num_node = 0;
function <void(int)> dfs = [&] (int u) -> void {
if(d[u]) return;
d[u] = true;
num_node++;
for (auto v : adj[u]) dfs(v);
};
for (int i = 0; i < N - 1; ++i) {
for (int j = 0; j < M; ++j) {
dfs(S[j][i]);
}
if(num_node == 1) {
ans++;
num_node = 0;
}
}
return ans;
}
#ifdef LOCAL
#include <cassert>
#include <cstdio>
#include <vector>
void taskcase() {
int N, M;
assert(2 == scanf("%d%d", &N, &M));
std::vector<int> F(N);
F[0] = -1;
for (int i = 1; i < N; ++i)
assert(1 == scanf("%d", &F[i]));
std::vector<std::vector<int>> S(M, std::vector<int>(N - 1));
for (int i = 0; i < M; ++i)
for (int j = 0; j < N - 1; ++j)
assert(1 == scanf("%d", &S[i][j]));
printf("%d\n", solve(N, M, F, S));
}
int main() {
freopen("TASK.inp", "r", stdin);
freopen("TASK.out", "w", stdout);
int T;
assert(1 == scanf("%d", &T));
while(T--) taskcase();
return 0;
}
#endif
// Dream it. Wish it. Do it.
컴파일 시 표준 에러 (stderr) 메시지
september.cpp: In function 'int solve(int, int, std::vector<int>, std::vector<std::vector<int> >)':
september.cpp:22:18: warning: unused variable 'res' [-Wunused-variable]
22 | int ans = 0, res = 0;
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |