이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 5;
int n, m, ti, bccID, tin[mx], low[mx]; long long ans, nn, sz[mx];
vector<int> adj[mx], bct[mx*2]; stack<int> stk;
void AP(int cur, int p = 0){
tin[cur] = ++ti; low[cur] = 1e9; stk.push(cur); nn++;
int c = 0;
for (int nxt : adj[cur]) if (nxt != p){
if (tin[nxt]) low[cur] = min(low[cur], tin[nxt]);
else{
AP(nxt, cur); c++;
low[cur] = min(low[cur], low[nxt]);
if (low[nxt] >= tin[cur]){
bccID++; bct[cur].push_back(bccID + n);
while (1){
int tp = stk.top(); stk.pop();
bct[bccID + n].push_back(tp);
if (tp == nxt) break;
}
}
}
}
}
void dfs(int cur){
sz[cur] = (cur <= nn);
for (int nxt : bct[cur]){
dfs(nxt); sz[cur] += sz[nxt];
if (cur > n) ans -= bct[cur].size() * sz[nxt] * (sz[nxt] - 1);
}
if (cur > n) ans -= bct[cur].size() * (nn - sz[cur]) * (nn - sz[cur] - 1);
}
int main(){
cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
adj[a].push_back(b); adj[b].push_back(a);
}
for (int i = 1; i <= n; i++) if (!tin[i]){
nn = 0; AP(i);
ans += nn * (nn - 1) * (nn - 2);
dfs(i);
}
cout<<ans<<"\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |