Submission #393967

#TimeUsernameProblemLanguageResultExecution timeMemory
39396779brueDuathlon (APIO18_duathlon)C++14
0 / 100
75 ms21152 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int n, m; vector<int> link[100002]; ll ans; void input(); void makeBCC(); int main(){ input(); makeBCC(); printf("%lld", ans); } void input(){ scanf("%d %d", &n, &m); for(int i=1; i<=m; i++){ int x, y; scanf("%d %d", &x, &y); link[x].push_back(y); link[y].push_back(x); } } bool seen[100002]; ll seenCnt; int dfsn[100002]; int dcnt; stack<pair<int, int> > stk; vector<vector<pair<int, int> > > BCC; int dfs(int x, int prv = -1){ int result = dfsn[x] = ++dcnt; seenCnt++; for(auto y: link[x]){ if(prv == y) continue; if(dfsn[x] > dfsn[y]) stk.push(make_pair(x, y)); if(dfsn[y] > 0) result = min(result, dfsn[y]); else{ int tmp = dfs(y, x); result = min(result, tmp); if(tmp >= dfsn[x]){ vector<pair<int, int> > currBCC; while(!stk.empty() && stk.top() != make_pair(x, y)){ currBCC.push_back(stk.top()); stk.pop(); } currBCC.push_back(stk.top()); stk.pop(); BCC.push_back(currBCC); } } } return result; } void makeBCC(){ for(int i=1; i<=n; i++){ if(!seen[i]){ seenCnt = 0; dfs(i); ans += seenCnt * (seenCnt-1) * (seenCnt-2) / 3; } } }

Compilation message (stderr)

count_triplets.cpp: In function 'void input()':
count_triplets.cpp:21:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   21 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:24:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |         scanf("%d %d", &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...