#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mp make_pair
#define mid (l+r)/2
#define le node * 2
#define ri node * 2 + 1
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef pair<double,ll>pdi;
const ll inf=1e18;
const ll mod=987654321;
const ld Pi=acos(-1);
ll n , m , ans , nodes , edges ;
vll v [100009] ;
ll dp [100009] , done [100009] ; ;
void calc ( int node ) {
if ( done [node] ) return ;
done [node] = 1 ;
nodes ++ , edges += v [node] .size () ;
for ( auto u : v [node] )
calc ( u ) ;
}
void solve ( int node , int p ) {
dp [node] = 1 ;
for ( auto u : v [node] ) {
if ( u == p ) C ;
solve ( u , node ) ;
dp [node] += dp [u] ;
}
ll sum = 0 , up = nodes - dp [node] ;
for ( auto u : v [node] ) {
if ( u == p ) C ;
ans += up * dp [u] * 2ll ;
ans += sum * dp [u] * 2ll ;
sum += dp [u] ;
}
}
int main () {
cin >> n >> m ;
for ( int i = 0 ; i < m ; i ++ ) {
int a , b ;
cin >> a >> b ;
a -- , b -- ;
v [a] .pb ( b ) ;
v [b] .pb ( a ) ;
}
for ( int i = 0 ; i < n ; i ++ ) {
if ( done [i] ) C ;
nodes = 0 , edges = 0 ;
calc ( i ) ;
if ( nodes * 2ll == edges ) {
if ( nodes >= 3ll ) {
ans += ( nodes ) * ( nodes - 1ll ) * ( nodes - 2ll ) ;
}
}
else
solve ( i , i ) ;
}
cout << ans << endl ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
537 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
537 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
122 ms |
9724 KB |
Output is correct |
2 |
Correct |
134 ms |
9880 KB |
Output is correct |
3 |
Correct |
138 ms |
10744 KB |
Output is correct |
4 |
Correct |
127 ms |
10872 KB |
Output is correct |
5 |
Correct |
125 ms |
10616 KB |
Output is correct |
6 |
Correct |
130 ms |
11244 KB |
Output is correct |
7 |
Correct |
129 ms |
10104 KB |
Output is correct |
8 |
Correct |
132 ms |
10360 KB |
Output is correct |
9 |
Correct |
128 ms |
9336 KB |
Output is correct |
10 |
Correct |
130 ms |
9720 KB |
Output is correct |
11 |
Correct |
106 ms |
8340 KB |
Output is correct |
12 |
Correct |
107 ms |
8240 KB |
Output is correct |
13 |
Correct |
92 ms |
8184 KB |
Output is correct |
14 |
Correct |
106 ms |
8184 KB |
Output is correct |
15 |
Correct |
71 ms |
7416 KB |
Output is correct |
16 |
Correct |
68 ms |
7420 KB |
Output is correct |
17 |
Correct |
4 ms |
4224 KB |
Output is correct |
18 |
Correct |
3 ms |
4224 KB |
Output is correct |
19 |
Correct |
4 ms |
4224 KB |
Output is correct |
20 |
Correct |
4 ms |
4224 KB |
Output is correct |
21 |
Correct |
4 ms |
4224 KB |
Output is correct |
22 |
Correct |
4 ms |
4224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
2688 KB |
Output is correct |
2 |
Correct |
2 ms |
2688 KB |
Output is correct |
3 |
Correct |
3 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2816 KB |
Output is correct |
5 |
Correct |
3 ms |
2816 KB |
Output is correct |
6 |
Correct |
3 ms |
2816 KB |
Output is correct |
7 |
Correct |
3 ms |
2816 KB |
Output is correct |
8 |
Correct |
3 ms |
2816 KB |
Output is correct |
9 |
Correct |
3 ms |
2688 KB |
Output is correct |
10 |
Correct |
3 ms |
2688 KB |
Output is correct |
11 |
Correct |
3 ms |
2688 KB |
Output is correct |
12 |
Correct |
3 ms |
2688 KB |
Output is correct |
13 |
Correct |
3 ms |
2688 KB |
Output is correct |
14 |
Correct |
4 ms |
2688 KB |
Output is correct |
15 |
Correct |
3 ms |
2688 KB |
Output is correct |
16 |
Correct |
3 ms |
2688 KB |
Output is correct |
17 |
Correct |
3 ms |
2688 KB |
Output is correct |
18 |
Correct |
3 ms |
2688 KB |
Output is correct |
19 |
Correct |
3 ms |
2688 KB |
Output is correct |
20 |
Correct |
4 ms |
2688 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
143 ms |
8184 KB |
Output is correct |
2 |
Correct |
137 ms |
8440 KB |
Output is correct |
3 |
Correct |
156 ms |
8456 KB |
Output is correct |
4 |
Correct |
127 ms |
8440 KB |
Output is correct |
5 |
Correct |
128 ms |
8440 KB |
Output is correct |
6 |
Correct |
137 ms |
12152 KB |
Output is correct |
7 |
Correct |
149 ms |
11384 KB |
Output is correct |
8 |
Correct |
136 ms |
10488 KB |
Output is correct |
9 |
Correct |
133 ms |
9848 KB |
Output is correct |
10 |
Correct |
125 ms |
8440 KB |
Output is correct |
11 |
Correct |
131 ms |
8440 KB |
Output is correct |
12 |
Correct |
127 ms |
8440 KB |
Output is correct |
13 |
Correct |
124 ms |
8440 KB |
Output is correct |
14 |
Correct |
110 ms |
8316 KB |
Output is correct |
15 |
Correct |
101 ms |
8056 KB |
Output is correct |
16 |
Correct |
62 ms |
7160 KB |
Output is correct |
17 |
Correct |
105 ms |
8704 KB |
Output is correct |
18 |
Correct |
111 ms |
8680 KB |
Output is correct |
19 |
Correct |
120 ms |
8672 KB |
Output is correct |
20 |
Correct |
121 ms |
8680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
2688 KB |
Output is correct |
2 |
Correct |
3 ms |
2688 KB |
Output is correct |
3 |
Runtime error |
665 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
8184 KB |
Output is correct |
2 |
Correct |
126 ms |
8312 KB |
Output is correct |
3 |
Runtime error |
927 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
537 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
537 ms |
1048580 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |