Submission #136220

# Submission time Handle Problem Language Result Execution time Memory
136220 2019-07-25T03:38:29 Z baluteshih Duathlon (APIO18_duathlon) C++14
31 / 100
124 ms 21780 KB
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define ET cout << "\n"
#define F first
#define S second
#define MP make_pair
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define DB(a,s,e) {for(int i=s;i<e;++i) cout << a[i] << " ";ET;};
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

vector<ll> G[100005],BG[100005];
ll low[100005],dfn[100005],bln[100005],avsub[100005],sub[100005],nBcc,dft;
ll ans1,ans2,c;
stack<ll> st;
bitset<100005> vis;

void con(int u)
{
	vis[u]=1,++c;
	for(ll i:G[u])
		if(!vis[i])
			con(i);
}

void dfs(int u,int f)
{
	ll usq=0;
	low[u]=dfn[u]=++dft,sub[u]=1;
	st.push(u);
	vector<int> v;
	for(ll i:G[u])
		if(i!=f)
			if(!dfn[i])
			{
				dfs(i,u),sub[u]+=sub[i];
				if(low[i]>=dfn[u])
				{
					ll sz=0,sq=0;
					avsub[u]+=sub[i],usq+=sub[i]*sub[i],++nBcc;
					for(int x=-1;x!=i;)
					{
						x=st.top(),st.pop(),bln[x]=nBcc,++sz;
						sq+=avsub[x]*avsub[x];
					}
					ans1+=sz*(sz-1)*(sz-2),ans1+=sz*(sz-1),ans2+=sz*(sz-1)*(c-sz);
					sq+=(c-sub[i])*(c-sub[i]),ans1+=sz*((c-sz)*(c-sz)-sq);
				}
				else
					low[u]=min(low[u],low[i]);
			}
			else if(dfn[u]>dfn[i])
				low[u]=min(low[u],dfn[i]);
	ans1+=avsub[u]*avsub[u]-usq;
}


int main()
{jizz
	ll m,a,b,n;
	cin >> n >> m;
	while(m--)
		cin >> a >> b,G[a].pb(b),G[b].pb(a);
	for(int i=1;i<=n;++i)
		if(!vis[i])
			c=0,con(i),dfs(i,i);
	cout << ans1+ans2*2 << "\n";
}

Compilation message

count_triplets.cpp: In function 'void dfs(int, int)':
count_triplets.cpp:37:5: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if(i!=f)
     ^
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 118 ms 21780 KB Output is correct
2 Correct 124 ms 21624 KB Output is correct
3 Correct 115 ms 17320 KB Output is correct
4 Correct 119 ms 21056 KB Output is correct
5 Correct 88 ms 16760 KB Output is correct
6 Correct 105 ms 16760 KB Output is correct
7 Correct 101 ms 15352 KB Output is correct
8 Correct 105 ms 16176 KB Output is correct
9 Correct 95 ms 14428 KB Output is correct
10 Correct 98 ms 15328 KB Output is correct
11 Correct 76 ms 13304 KB Output is correct
12 Correct 71 ms 13176 KB Output is correct
13 Correct 70 ms 13176 KB Output is correct
14 Correct 74 ms 13048 KB Output is correct
15 Correct 54 ms 12664 KB Output is correct
16 Correct 49 ms 12600 KB Output is correct
17 Correct 12 ms 9080 KB Output is correct
18 Correct 12 ms 9208 KB Output is correct
19 Correct 12 ms 8952 KB Output is correct
20 Correct 12 ms 9080 KB Output is correct
21 Correct 11 ms 8824 KB Output is correct
22 Correct 11 ms 8824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 5112 KB Output is correct
2 Correct 7 ms 5112 KB Output is correct
3 Correct 7 ms 5240 KB Output is correct
4 Correct 7 ms 5240 KB Output is correct
5 Correct 7 ms 5240 KB Output is correct
6 Correct 7 ms 5240 KB Output is correct
7 Correct 7 ms 5244 KB Output is correct
8 Correct 7 ms 5112 KB Output is correct
9 Correct 8 ms 5128 KB Output is correct
10 Correct 7 ms 5112 KB Output is correct
11 Correct 8 ms 5112 KB Output is correct
12 Correct 7 ms 5112 KB Output is correct
13 Correct 7 ms 5116 KB Output is correct
14 Correct 7 ms 5112 KB Output is correct
15 Correct 7 ms 5112 KB Output is correct
16 Correct 6 ms 5112 KB Output is correct
17 Correct 8 ms 5116 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 7 ms 5240 KB Output is correct
20 Correct 7 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 12792 KB Output is correct
2 Correct 80 ms 12792 KB Output is correct
3 Correct 84 ms 12776 KB Output is correct
4 Correct 84 ms 12796 KB Output is correct
5 Correct 82 ms 12792 KB Output is correct
6 Correct 110 ms 17912 KB Output is correct
7 Correct 100 ms 16476 KB Output is correct
8 Correct 102 ms 15508 KB Output is correct
9 Correct 104 ms 14584 KB Output is correct
10 Correct 93 ms 12796 KB Output is correct
11 Correct 83 ms 14072 KB Output is correct
12 Correct 78 ms 13944 KB Output is correct
13 Correct 79 ms 13944 KB Output is correct
14 Correct 71 ms 13816 KB Output is correct
15 Correct 67 ms 13432 KB Output is correct
16 Correct 42 ms 12360 KB Output is correct
17 Correct 62 ms 13420 KB Output is correct
18 Correct 59 ms 13416 KB Output is correct
19 Correct 57 ms 13412 KB Output is correct
20 Correct 59 ms 13436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5240 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Incorrect 7 ms 5112 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 94 ms 12856 KB Output is correct
2 Correct 89 ms 12664 KB Output is correct
3 Incorrect 98 ms 13228 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 4984 KB Output is correct
6 Correct 6 ms 5112 KB Output is correct
7 Incorrect 6 ms 4984 KB Output isn't correct
8 Halted 0 ms 0 KB -