제출 #283437

#제출 시각아이디문제언어결과실행 시간메모리
283437evpipis철인 이종 경기 (APIO18_duathlon)C++11
100 / 100
299 ms39144 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define pb push_back #define mp make_pair typedef pair<int, int> ii; typedef long long ll; const int len = 2e5+5; int num[len], low[len], sz[len], sub[len], vis[len], par[len]; int cnt_dfs, cnt_com, n, m; ii edge[len]; vector<int> com[len], nex[len], stck; vector<ii> adj[len]; // the graph is simple // but the dfs is general void dfs(int u, int root = 0){ num[u] = low[u] = ++cnt_dfs; for (auto v: adj[u]){ if (!vis[v.se] && !num[v.fi]){ vis[v.se] = 1, stck.pb(v.se); dfs(v.fi); low[u] = min(low[u], low[v.fi]); if (low[v.fi] >= num[u]){ cnt_com++; while (true){ int e = stck.back(); stck.pop_back(); com[cnt_com].pb(e); if (e == v.se) break; } } } else if (!vis[v.se] && num[v.fi]){ vis[v.se] = 1, stck.pb(v.se); low[u] = min(low[u], num[v.fi]); } } } void compose(){ for (int i = 1; i <= cnt_com; i++){ set<int> mys; for (auto e: com[i]){ int a = edge[e].fi, b = edge[e].se; mys.insert(a), mys.insert(b); } for (auto u: mys){ sz[i+n]++; nex[u].pb(i+n); nex[i+n].pb(u); } } } void fix(int u){ if (u <= n) sub[u] = 1; for (auto v: nex[u]){ if (v == par[u]) continue; par[v] = u; fix(v); sub[u] += sub[v]; } } ll solve(int u, int all){ ll ans = 0; if (u > n){ for (auto v: nex[u]){ int sb = sub[v]; if (v == par[u]) sb = all-sub[u]; ans += (sz[u]-1)*1LL*(sb)*1LL*(sb-1); } } for (auto v: nex[u]) if (v != par[u]) ans += solve(v, all); return ans; } int main(){ scanf("%d %d", &n, &m); for (int i = 0; i < m; i++){ int a, b; scanf("%d %d", &a, &b); adj[a].pb(mp(b, i)); adj[b].pb(mp(a, i)); edge[i] = mp(a, b); } for (int i = 1; i <= n; i++) if (!num[i]) dfs(i, 1); compose(); ll ans = 0; for (int i = 1; i <= n; i++) if (!par[i]) fix(i), ans += (sub[i])*1LL*(sub[i]-1)*1LL*(sub[i]-2) - solve(i, sub[i]); printf("%lld\n", ans); return 0; }

컴파일 시 표준 에러 (stderr) 메시지

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   99 |     scanf("%d %d", &n, &m);
      |     ~~~~~^~~~~~~~~~~~~~~~~
count_triplets.cpp:102:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  102 |         scanf("%d %d", &a, &b);
      |         ~~~~~^~~~~~~~~~~~~~~~~
#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...