#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T> void qqbx(const char *s, const H &h, T ...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
#define pb emplace_back
#define sort_uni(v) sort(begin(v),end(v)),v.erase(unique(begin(v),end(v)),end(v))
using namespace std;
typedef long long ll;
const int N = 100025;
vector<int> g[N];
int vis[N];
ll ans = 0;
int dfs(int i) {
int s = 1;
vis[i] = 1;
for(int j: g[i]) if(!vis[j]) s += dfs(j);
return s;
}
int dfs2(int i, int n) {
int s = 0;
vis[i] = -1;
for(int j: g[i]) if(~vis[j]) {
int t = dfs2(j, n);
ans += 1LL * t * s;
s += t;
}
ans += 1LL * s * (n-s-1);
return ++s;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 0; i < m; i++) {
int a, b;
cin >> a >> b;
g[a].pb(b), g[b].pb(a);
}
for(int i = 1; i <= n; i++) if(!vis[i]) {
int s = dfs(i);
dfs2(i, s);
}
cout << ans*2 << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
99 ms |
10872 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2720 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
2 ms |
2688 KB |
Output is correct |
5 |
Correct |
3 ms |
2688 KB |
Output is correct |
6 |
Correct |
2 ms |
2688 KB |
Output is correct |
7 |
Correct |
2 ms |
2688 KB |
Output is correct |
8 |
Correct |
2 ms |
2688 KB |
Output is correct |
9 |
Correct |
2 ms |
2688 KB |
Output is correct |
10 |
Correct |
2 ms |
2688 KB |
Output is correct |
11 |
Correct |
2 ms |
2688 KB |
Output is correct |
12 |
Correct |
2 ms |
2688 KB |
Output is correct |
13 |
Correct |
2 ms |
2688 KB |
Output is correct |
14 |
Correct |
2 ms |
2688 KB |
Output is correct |
15 |
Correct |
2 ms |
2688 KB |
Output is correct |
16 |
Correct |
2 ms |
2688 KB |
Output is correct |
17 |
Correct |
2 ms |
2688 KB |
Output is correct |
18 |
Correct |
2 ms |
2688 KB |
Output is correct |
19 |
Correct |
2 ms |
2688 KB |
Output is correct |
20 |
Correct |
2 ms |
2688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
6264 KB |
Output is correct |
2 |
Correct |
100 ms |
7056 KB |
Output is correct |
3 |
Correct |
83 ms |
7032 KB |
Output is correct |
4 |
Correct |
84 ms |
7052 KB |
Output is correct |
5 |
Correct |
89 ms |
7036 KB |
Output is correct |
6 |
Correct |
112 ms |
9592 KB |
Output is correct |
7 |
Correct |
75 ms |
8572 KB |
Output is correct |
8 |
Correct |
98 ms |
8184 KB |
Output is correct |
9 |
Correct |
81 ms |
7800 KB |
Output is correct |
10 |
Correct |
58 ms |
7032 KB |
Output is correct |
11 |
Correct |
78 ms |
7032 KB |
Output is correct |
12 |
Correct |
71 ms |
7032 KB |
Output is correct |
13 |
Correct |
76 ms |
7032 KB |
Output is correct |
14 |
Correct |
68 ms |
6904 KB |
Output is correct |
15 |
Correct |
52 ms |
6776 KB |
Output is correct |
16 |
Correct |
36 ms |
5888 KB |
Output is correct |
17 |
Correct |
42 ms |
7280 KB |
Output is correct |
18 |
Correct |
42 ms |
7280 KB |
Output is correct |
19 |
Correct |
41 ms |
7276 KB |
Output is correct |
20 |
Correct |
52 ms |
7356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
2688 KB |
Output is correct |
2 |
Correct |
3 ms |
2688 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
79 ms |
6368 KB |
Output is correct |
2 |
Correct |
88 ms |
6904 KB |
Output is correct |
3 |
Incorrect |
106 ms |
7032 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2688 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |