# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
701512 | 2023-02-21T11:40:35 Z | Abrar_Al_Samit | Duathlon (APIO18_duathlon) | C++17 | 446 ms | 1048576 KB |
#include<bits/stdc++.h> using namespace std; const int nax = 1002; vector<int>g[nax]; int n, m; long long ans = 0; bool vis[nax]; int sub[nax]; int dfs1(int v, int p) { sub[v] = 1; vis[v] = 1; for(int u : g[v]) if(u!=p) { sub[v] += dfs1(u, v); } return sub[v]; } void dfs2(int v,int p, int anc) { for(int i=0; i<g[v].size(); ++i) if(g[v][i]!=p) { dfs2(g[v][i], v, anc+1); for(int j=i+1; j<g[v].size(); ++j) if(g[v][j]!=p) { ans += sub[g[v][i]] * 1LL * sub[g[v][j]]; } } ans += (sub[v]-1) * 1LL * anc; } void PlayGround() { cin>>n>>m; for(int i=0; i<m; ++i) { int u, v; cin>>u>>v; g[u].push_back(v); g[v].push_back(u); } for(int i=1; i<=n; ++i) if(!vis[i]) { dfs1(i, i); dfs2(i, i, 0); } cout<<ans*2<<'\n'; // cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); PlayGround(); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 446 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 446 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 468 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 468 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 340 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 468 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 446 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 446 ms | 1048576 KB | Execution killed with signal 9 |
2 | Halted | 0 ms | 0 KB | - |