This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fast cin.tie(0)->sync_with_stdio(0);
#define int long long
#define inf ((int)1e18)
using namespace std;
const int N = 100005;
vector <int> adj[N];
int dp[N][4];
void dfs(int node, int ata) {
// dp[node][0] = 1;
dp[node][1] = 1;
for(auto it:adj[node]) {
if(it == ata) continue;
dfs(it, node);
dp[node][3] += dp[it][3] + dp[it][2];
dp[node][2] += dp[it][2] + dp[it][1];
dp[node][1] += dp[it][1] + dp[it][0];
}
// cout << node << ": " << dp[node][1] << dp[node][2] << dp[node][3] << '\n';
}
int32_t main(){
fast
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, 1);
cout << dp[1][3] * 2;
}
# | 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... |