Submission #393334

#TimeUsernameProblemLanguageResultExecution timeMemory
393334parsabahramiDuathlon (APIO18_duathlon)C++17
8 / 100
85 ms9632 KiB
/* There's someone in my head but it's not me */ #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<int, int> pii; #define SZ(x) (int) x.size() #define F first #define S second const int N = 1e5 + 10, MOD = 1e9 + 7; int s, n, m, M[N], f = 1; vector<int> adj[N]; void DFS(int v) { s++; M[v] = 1; if (SZ(adj[v]) < 2) f = 0; for (int u : adj[v]) if (!M[u]) DFS(u); } int main() { scanf("%d%d", &n, &m); for (int i = 1; i <= m; i++) { int u, v; scanf("%d%d", &u, &v); adj[u].push_back(v); adj[v].push_back(u); assert(SZ(adj[u]) < 3); assert(SZ(adj[v]) < 3); } ll ret = 0; for (int i = 1; i <= n; i++) { if (M[i]) continue; s = 0, f = 1; DFS(i); if (f) ret += 1ll * s * (s - 1) * (s - 2); else ret += 1ll * s * (s - 1) * (s - 2) / 3; } printf("%lld\n", ret); return 0; }

Compilation message (stderr)

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