#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << "[" << H << "]";
debug_out(T...);
}
#ifdef dddxxz
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
#define SZ(s) ((int)s.size())
#define all(x) (x).begin(), (x).end()
#define revall(x) (x).rbegin(), (x).rend()
clock_t startTime;
double getCurrentTime() {
return (double) (clock() - startTime) / CLOCKS_PER_SEC;
}
typedef long long ll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const double eps = 0.00001;
const int MOD = 1e9 + 7;
const int INF = 1000000101;
const long long LLINF = 1223372000000000555;
const int N = 1e6 + 3e2;
const int M = 2222;
int n, m;
vector<int> g[N];
int cnt = 0, color[N];
bool cycle = false;
void dfs(int v, int p){
color[v] = 1;
cnt++;
for (int u : g[v]){
if (u == p) continue;
if (color[u] == 1) cycle = true;
if (color[u] == 0) dfs(u, v);
}
color[v] = 2;
}
void Subtask_3(){
ll ans = 0;
for (int i = 1; i <= n; i++){
if (color[i] == 0){
cnt = 0;
cycle = false;
dfs(i, 0);
ans += 1ll * cnt * (cnt - 1) * (cnt - 2) / (cycle ? 1 : 3);
}
}
cout << ans;
exit(0);
}
ll ans5 = 0;
int subtree[N];
void dfs2(int v, int p){
subtree[v] = 1;
for (int u : g[v]){
if (u != p){
dfs2(u, v);
subtree[v] += subtree[u];
}
}
for (int u : g[v]){
if (u != p){
ll x = subtree[u], y = n - subtree[u] - 1;
ans5 += x * y;
} else {
ll x = subtree[v] - 1, y = n - x - 1;
ans5 += x * y;
}
}
}
void Subtask_5(){
dfs2(1, 1);
cout << ans5 << endl;
exit(0);
}
void solve(int TC) {
cin >> n >> m;
bool ok3 = true;
while (m--) {
int u, v;
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
ok3 &= g[u].size() <= 2;
ok3 &= g[v].size() <= 2;
}
if (ok3){
Subtask_3();
}
Subtask_5();
}
int main() {
startTime = clock();
cin.tie(nullptr); cout.tie(nullptr);
ios_base::sync_with_stdio(false);
bool llololcal = false;
#ifdef dddxxz
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
llololcal = true;
#endif
int TC = 1;
// cin >> TC;
for (int test = 1; test <= TC; test++) {
//debug(test);
//cout << "Case #" << test << ": ";
solve(test);
}
if (llololcal) cerr << endl << "Time: " << int(getCurrentTime() * 1000) << " ms" << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
568 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
568 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
31440 KB |
Output is correct |
2 |
Correct |
69 ms |
31848 KB |
Output is correct |
3 |
Correct |
65 ms |
30220 KB |
Output is correct |
4 |
Correct |
84 ms |
30932 KB |
Output is correct |
5 |
Correct |
67 ms |
29560 KB |
Output is correct |
6 |
Correct |
66 ms |
29604 KB |
Output is correct |
7 |
Correct |
66 ms |
29176 KB |
Output is correct |
8 |
Correct |
67 ms |
29468 KB |
Output is correct |
9 |
Correct |
67 ms |
28808 KB |
Output is correct |
10 |
Correct |
67 ms |
29232 KB |
Output is correct |
11 |
Correct |
63 ms |
28352 KB |
Output is correct |
12 |
Correct |
55 ms |
28148 KB |
Output is correct |
13 |
Correct |
52 ms |
28076 KB |
Output is correct |
14 |
Correct |
56 ms |
27968 KB |
Output is correct |
15 |
Correct |
44 ms |
27408 KB |
Output is correct |
16 |
Correct |
44 ms |
27304 KB |
Output is correct |
17 |
Correct |
17 ms |
24136 KB |
Output is correct |
18 |
Correct |
16 ms |
24228 KB |
Output is correct |
19 |
Correct |
18 ms |
24200 KB |
Output is correct |
20 |
Correct |
18 ms |
24140 KB |
Output is correct |
21 |
Correct |
17 ms |
24168 KB |
Output is correct |
22 |
Correct |
17 ms |
24212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
23856 KB |
Output is correct |
2 |
Correct |
16 ms |
23812 KB |
Output is correct |
3 |
Correct |
17 ms |
23756 KB |
Output is correct |
4 |
Correct |
17 ms |
23824 KB |
Output is correct |
5 |
Correct |
19 ms |
23884 KB |
Output is correct |
6 |
Correct |
17 ms |
23832 KB |
Output is correct |
7 |
Correct |
17 ms |
23756 KB |
Output is correct |
8 |
Correct |
17 ms |
23828 KB |
Output is correct |
9 |
Correct |
17 ms |
23828 KB |
Output is correct |
10 |
Incorrect |
17 ms |
23824 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
28392 KB |
Output is correct |
2 |
Correct |
69 ms |
28592 KB |
Output is correct |
3 |
Correct |
65 ms |
28608 KB |
Output is correct |
4 |
Correct |
67 ms |
28716 KB |
Output is correct |
5 |
Correct |
63 ms |
28672 KB |
Output is correct |
6 |
Correct |
66 ms |
30276 KB |
Output is correct |
7 |
Correct |
74 ms |
31344 KB |
Output is correct |
8 |
Correct |
74 ms |
30704 KB |
Output is correct |
9 |
Correct |
68 ms |
29964 KB |
Output is correct |
10 |
Incorrect |
64 ms |
28648 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
23768 KB |
Output is correct |
2 |
Correct |
16 ms |
23832 KB |
Output is correct |
3 |
Runtime error |
742 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
66 ms |
28460 KB |
Output is correct |
2 |
Correct |
66 ms |
28552 KB |
Output is correct |
3 |
Runtime error |
867 ms |
1048580 KB |
Execution killed with signal 9 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
568 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
568 ms |
1048580 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |