# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
710273 |
2023-03-15T06:28:27 Z |
lam |
Duathlon (APIO18_duathlon) |
C++14 |
|
1000 ms |
1048576 KB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int maxn = 1e5 + 10;
int n,m;
vector <int> adj[maxn];
int dp[maxn],dp2[maxn],s[maxn];
bool dau[maxn];
vector <int> root;
void dfs(int x, int p)
{
dau[x] = 1;
dp[x] = 0;
for (int i:adj[x])
if (i!=p)
{
dfs(i,x);
dp[x] += dp[i]+1;
}
}
void dfs2(int x, int p, int val)
{
dp2[x] = val;
val++;
vector <int> pre,suf;
for (int i:adj[x])
if (i!=p)
{
pre.push_back(dp[i]+1);
suf.push_back(dp[i]+1);
}
for (int i=1; i<pre.size(); i++) pre[i]+=pre[i-1];
for (int i=suf.size()-2; i>=0; i--) suf[i]+=suf[i+1];
int cnt=0;
for (int i:adj[x])
if (i!=p)
{
int val2 = val;
if (cnt>0) val2 += pre[cnt-1];
if (cnt<(int)suf.size()-1) val2+=suf[cnt+1];
cnt++;
dfs2(i,x,val2);
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n>>m;
for (int i=1; i<=m; i++)
{
int u,v; cin>>u>>v;
adj[u].push_back(v);
adj[v].push_back(u);
}
for (int i=1; i<=n; i++) if (!dau[i]) dfs(i,i), root.push_back(i);
for (int i:root) dfs2(i,i,0);
int ans=0;
for (int i=1; i<=n; i++)
{
ans += 2*dp[i]*dp2[i];
}
cout<<ans<<'\n';
}
Compilation message
count_triplets.cpp: In function 'void dfs2(long long int, long long int, long long int)':
count_triplets.cpp:33:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i=1; i<pre.size(); i++) pre[i]+=pre[i-1];
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
623 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
623 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1099 ms |
504460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
69 ms |
8060 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
74 ms |
8024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
623 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
623 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |