이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "joitour.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, q;
vector<ll> f, dp, order;
vector<vector<ll>> adj, cou;
void dfs(int u, int p) {
for (ll& v : adj[u]) {
if (v == p) {
swap(v, adj[u].back());
adj[u].pop_back();
break;
}
}
for (int v : adj[u]) {
dfs(v, u);
}
order.push_back(u);
}
void init(int N, std::vector<int> F, std::vector<int> U, std::vector<int> V, int Q) {
n = N, q = Q;
f.resize(N);
dp.resize(N);
cou.resize(3, vector<ll>(N));
adj.resize(N);
for (int i = 0; i < N; i++) {
f[i] = F[i];
}
for (int j = 0; j < N - 1; j++) {
adj[U[j]].push_back(V[j]);
adj[V[j]].push_back(U[j]);
}
dfs(0, -1);
}
void change(int X, int Y) {
f[X] = Y;
}
long long num_tours() {
for (int u = 0; u < n; u++) {
dp[u] = cou[0][u] = cou[1][u] = cou[2][u] = 0;
}
for (int u : order) {
cou[f[u]][u] = 1;
for (int v : adj[u]) {
for (int i = 0; i < 3; i++) {
cou[i][u] += cou[i][v];
}
}
}
ll sum = 0;
for (int u : order) {
if (f[u] == 1) {
ll sum = 0;
for (int v : adj[u]) {
sum += cou[0][v] * cou[2][v];
}
dp[u] += cou[0][u] * cou[2][u] - sum;
dp[u] += cou[0][u] * (cou[2][0] - cou[2][u]);
dp[u] += cou[2][u] * (cou[0][0] - cou[0][u]);
}
for (int v : adj[u]) {
dp[u] += dp[v];
}
}
return dp[0];
}
컴파일 시 표준 에러 (stderr) 메시지
joitour.cpp: In function 'long long int num_tours()':
joitour.cpp:62:8: warning: unused variable 'sum' [-Wunused-variable]
62 | ll sum = 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... |