Submission #977701

# Submission time Handle Problem Language Result Execution time Memory
977701 2024-05-08T09:38:13 Z huutuan Duathlon (APIO18_duathlon) C++14
0 / 100
117 ms 59984 KB
#include<bits/stdc++.h>

using namespace std;

#define int long long

const int N=2e5+10;
int n, m;
vector<int> g[N];
int num[N], low[N], tdfs;
stack<pair<int, int>> stk;
vector<pair<int, int>> bcc[N];
int cnt=0, cc[N], sz[N];
bool joint[N];
vector<int> gg[N];

void dfs_joint(int u, int p){
   num[u]=low[u]=++tdfs;
   int child=0;
   for (int v:g[u]){
      if (v==p) continue;
      if (!num[v]){
         ++child;
         stk.emplace(u, v);
         dfs_joint(v, u);
         low[u]=min(low[u], low[v]);
         if (low[v]>=num[u]){
            joint[u]=1;
            ++cnt;
            pair<int, int> edge={-1, -1};
            do{
               edge=stk.top(); stk.pop();
               bcc[cnt].emplace_back(edge);
            }while (edge!=make_pair(u, v));
         }
      }else low[u]=min(low[u], low[v]);
   }
   if (!p) joint[u]=child>=2;
}

int ans;
int sub_sz[N];

void dfs_sz(int u, int p){
   sub_sz[u]=u>n?sz[u]:1;
   for (int v:gg[u]) if (v!=p) dfs_sz(v, u), sub_sz[u]+=sub_sz[v];
}

void dfs(int u, int p){
   if (u>n){
      ans+=sz[u]*(sz[u]-1)*(sz[u]-2);
      ans+=sz[u]*(sz[u]-1)*(n-sz[u])*2;
      ans+=sz[u]*(n-sz[u])*(n-sz[u]-1);
      for (int v:gg[u]){
         if (v==p) ans-=sz[u]*(n-sub_sz[u])*(n-sub_sz[u]-1);
         else ans-=sz[u]*sub_sz[v]*(sub_sz[v]-1);
      }
   }else{
      ans+=(n-1)*(n-2);
      for (int v:gg[u]){
         if (v==p) ans-=(n-sub_sz[u])*(n-sub_sz[u]-1);
         else ans-=sub_sz[v]*(sub_sz[v]-1);
      }
      for (int v:gg[u]) ans+=(sz[v]+(int)gg[v].size()-1)*(sz[v]+(int)gg[v].size()-2);
   }
   for (int v:gg[u]) if (v!=p) dfs(v, u);
}

int32_t main(){
   ios_base::sync_with_stdio(false);
   cin.tie(nullptr);
   cin >> n >> m;
   for (int i=1; i<=m; ++i){
      int u, v; cin >> u >> v;
      g[u].push_back(v);
      g[v].push_back(u);
   }
   dfs_joint(1, 0);
   set<pair<int, int>> edge;
   for (int i=1; i<=n; ++i) if (joint[i]) cc[i]=i;
   for (int i=1; i<=cnt; ++i){
      for (auto &j:bcc[i]){
         if (!joint[j.first]) cc[j.first]=n+i;
         else edge.emplace(n+i, j.first);
         if (!joint[j.second]) cc[j.second]=n+i;
         else edge.emplace(n+i, j.second);
      }
   }
   for (int i=1; i<=n; ++i) if (cc[i]>n) ++sz[cc[i]];
   for (auto &i:edge){
      gg[i.first].push_back(i.second);
      gg[i.second].push_back(i.first);
   }
   dfs_sz(n+1, 0);
   dfs(n+1, 0);
   cout << ans << '\n';
   return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 22364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 22364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 47 ms 41300 KB Output is correct
2 Correct 54 ms 41164 KB Output is correct
3 Incorrect 38 ms 32468 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 22620 KB Output is correct
2 Correct 5 ms 22620 KB Output is correct
3 Correct 5 ms 22632 KB Output is correct
4 Correct 5 ms 22620 KB Output is correct
5 Correct 6 ms 22620 KB Output is correct
6 Correct 5 ms 22616 KB Output is correct
7 Correct 6 ms 22620 KB Output is correct
8 Correct 5 ms 22620 KB Output is correct
9 Correct 6 ms 22620 KB Output is correct
10 Incorrect 5 ms 22364 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 105 ms 44132 KB Output is correct
2 Correct 100 ms 43988 KB Output is correct
3 Correct 86 ms 44116 KB Output is correct
4 Correct 87 ms 43984 KB Output is correct
5 Correct 94 ms 43992 KB Output is correct
6 Correct 114 ms 59984 KB Output is correct
7 Correct 117 ms 51204 KB Output is correct
8 Correct 101 ms 49500 KB Output is correct
9 Correct 96 ms 47848 KB Output is correct
10 Incorrect 66 ms 36176 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 22616 KB Output is correct
2 Correct 5 ms 22616 KB Output is correct
3 Incorrect 5 ms 22364 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 44032 KB Output is correct
2 Correct 115 ms 44852 KB Output is correct
3 Incorrect 92 ms 42576 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 22364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 22364 KB Output isn't correct
2 Halted 0 ms 0 KB -