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>
// #include "jumps.h"
using namespace std;
// #define int long long
#define ll long long
#define ff first
#define ss second
#define pii pair <int, int>
#define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL)
const int inf = 1e9 + 9;
const int mxn = 2e5 + 2;
const int mod = 1e9 + 7;
vector<vector<int>> adj(mxn);
vector<int> chld(mxn);
vector<bool> did(mxn);
void dfs(int x) {
if(did[x]) return;
did[x] = 1;
for(auto a : adj[x]) {
if(!did[a]) {
chld[x]++;
dfs(a);
chld[x] += chld[a];
}
}
}
int main() {
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);
}
for(int i = 1; i <= n; i++) {
dfs(i);
}
// for(int i = 1; i <= n; i++) {
// cout << chld[i] << ' ';
// }
int ans = 0;
for(int i = 1; i <= n; i++) {
ans += chld[i] * (chld[i] - 1);
}
cout << ans;
cout << '\n';
}
# | 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... |