Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- void read(int &X){
- char c;
- do { c = getchar(); } while (!isalnum(c));
- X = c - '0';
- while (isalnum(c = getchar())) X = X * 10 + c - '0';
- }
- const int N = 2500 + 10;
- const int M = 5000 + 10;
- int n, m;
- vector<int > adj[N + M];
- int dist[N + M];
- queue<int > Q;
- void bfs(int root){
- memset(dist, 0x3f3f3f3f, sizeof dist);
- dist[root] = 0;
- while (!Q.empty()) Q.pop();
- Q.push(root);
- while (!Q.empty()){
- int u = Q.front(); Q.pop();
- for (int v : adj[u]){
- if (dist[v] != 0x3f3f3f3f) continue;
- dist[v] = dist[u] + 1;
- Q.push(v);
- }
- }
- }
- void solve(){
- long long ans = 0;
- for (int i = 1; i <= n; i++){
- bfs(i);
- for (int j = 1; j <= n; j++)
- ans += 1LL * dist[j];
- }
- ans /= 4;
- cout << ans << '\n';
- }
- int main(){
- // freopen("cliquegraph.in", "r", stdin);
- // freopen("cliquegraph.out", "w", stdout);
- read(n);
- read(m);
- for (int i = 1; i <= m; i++){
- int s;
- read(s);
- for (int j = 1; j <= s; j++){
- int u; read(u); u++;
- adj[u].push_back(i + n);
- adj[i + n].push_back(u);
- }
- }
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement