답안 #99843

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
99843 2019-03-07T19:17:26 Z TadijaSebez 철인 이종 경기 (APIO18_duathlon) C++11
31 / 100
261 ms 32276 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int N=200050;
vector<int> G[N],E[N];
void AddEdge(int u, int v){ E[u].pb(v);E[v].pb(u);}
int cnt,disc[N],low[N],tid,n,csz[N];
bool in[N];
stack<int> s;
void Tarjan(int u)
{
	disc[u]=low[u]=++tid;
	in[u]=1;s.push(u);
	for(int v:G[u])
	{
		if(!disc[v])
		{
			Tarjan(v);
			low[u]=min(low[u],low[v]);
			if(low[v]>=disc[u])
			{
				++cnt;
				AddEdge(u,cnt);
				csz[cnt]++;
				int h;
				do
				{
					h=s.top();
					s.pop();
					in[h]=0;
					AddEdge(h,cnt);
					csz[cnt]++;
				}while(h!=v);
			}
		}
		else if(in[v]) low[u]=min(low[u],disc[v]);
	}
}
ll ans;
int sz[N],dep[N],up[N];
void DFSSZ(int u, int p)
{
	sz[u]=u<=n;
	dep[u]=dep[p]+(u<=n);
	up[u]=n;
	for(int v:E[u]) if(v!=p) DFSSZ(v,u),sz[u]+=sz[v],up[u]-=sz[v];
}
int rt[N];
void Solve(int u, int p, int root)
{
	for(int v:E[u]) if(v!=p) Solve(v,u,root);
    ll all=(ll)sz[u]*(sz[u]-1);
    int ch=0;
    for(int v:E[u]) if(v!=p) all-=(ll)sz[v]*(sz[v]-1),ch+=csz[v]-1;
    if(u<=n) ans+=(ll)(sz[root]-1)*dep[p]*2;
    if(u<=n) ans-=all*(dep[u]+dep[p]);
    else ans-=all*(dep[u]+dep[p]-1);
    //printf("all:%lld\n",all);
	/*if(u<=n)
	{
		if(p) ans-=(ll)sz[u]*(csz[p]-1)*2*2;
		ans-=(ll)up[u]*ch*2*2;
		//printf("u:%i ans:%lld sz:%i up:%i dep:%i ch:%i csz[p]:%i\n",u,ans,sz[u],up[u],dep[u],ch,csz[p]);
	}*/
	if(u>n)
	{
		ans-=(ll)sz[root]*(csz[u]-1)*4;
		ans-=(ll)(csz[u]-1)*(csz[u]-2);
	}
	rt[u]=root;
	//else printf("u:%i ans:%i\n",u,ans);
}
int main()
{
	int m,u,v;
	scanf("%i %i",&n,&m);
	cnt=n;
	for(int i=1;i<=m;i++) scanf("%i %i",&u,&v),G[u].pb(v),G[v].pb(u);
	vector<int> root;
	for(int i=1;i<=n;i++) if(!disc[i]) Tarjan(i),root.pb(i);
	for(int i:root) DFSSZ(i,0),Solve(i,0,i);
	for(int i=n+1;i<=cnt;i++) ans+=(ll)csz[i]*(csz[i]-1)*sz[rt[i]]*2-(ll)csz[i]*(csz[i]-1)*(csz[i]-2);
	printf("%lld\n",ans);
	return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&m);
  ~~~~~^~~~~~~~~~~~~~~
count_triplets.cpp:79:55: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=m;i++) scanf("%i %i",&u,&v),G[u].pb(v),G[v].pb(u);
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9728 KB Output is correct
2 Correct 11 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 9 ms 9728 KB Output is correct
5 Correct 10 ms 9756 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Incorrect 11 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9728 KB Output is correct
2 Correct 11 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 9 ms 9728 KB Output is correct
5 Correct 10 ms 9756 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Incorrect 11 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 30132 KB Output is correct
2 Correct 151 ms 29936 KB Output is correct
3 Correct 177 ms 27888 KB Output is correct
4 Correct 171 ms 28528 KB Output is correct
5 Correct 164 ms 24876 KB Output is correct
6 Correct 156 ms 26996 KB Output is correct
7 Correct 134 ms 24952 KB Output is correct
8 Correct 186 ms 25464 KB Output is correct
9 Correct 243 ms 23416 KB Output is correct
10 Correct 162 ms 23576 KB Output is correct
11 Correct 148 ms 21340 KB Output is correct
12 Correct 127 ms 21112 KB Output is correct
13 Correct 135 ms 21108 KB Output is correct
14 Correct 129 ms 20800 KB Output is correct
15 Correct 95 ms 19856 KB Output is correct
16 Correct 116 ms 19736 KB Output is correct
17 Correct 17 ms 13048 KB Output is correct
18 Correct 17 ms 13048 KB Output is correct
19 Correct 17 ms 13048 KB Output is correct
20 Correct 17 ms 13048 KB Output is correct
21 Correct 17 ms 13048 KB Output is correct
22 Correct 17 ms 13048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 9856 KB Output is correct
2 Correct 11 ms 9984 KB Output is correct
3 Correct 12 ms 9856 KB Output is correct
4 Correct 14 ms 9984 KB Output is correct
5 Correct 13 ms 9984 KB Output is correct
6 Correct 12 ms 9984 KB Output is correct
7 Correct 13 ms 9984 KB Output is correct
8 Correct 12 ms 9984 KB Output is correct
9 Correct 12 ms 9856 KB Output is correct
10 Correct 13 ms 9828 KB Output is correct
11 Correct 12 ms 9984 KB Output is correct
12 Correct 12 ms 9856 KB Output is correct
13 Correct 14 ms 9884 KB Output is correct
14 Correct 11 ms 9828 KB Output is correct
15 Correct 13 ms 9856 KB Output is correct
16 Correct 14 ms 9856 KB Output is correct
17 Correct 11 ms 9856 KB Output is correct
18 Correct 13 ms 9984 KB Output is correct
19 Correct 13 ms 9856 KB Output is correct
20 Correct 11 ms 9984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 186 ms 23868 KB Output is correct
2 Correct 191 ms 23980 KB Output is correct
3 Correct 175 ms 24060 KB Output is correct
4 Correct 179 ms 24056 KB Output is correct
5 Correct 189 ms 23928 KB Output is correct
6 Correct 182 ms 32276 KB Output is correct
7 Correct 203 ms 29432 KB Output is correct
8 Correct 261 ms 28152 KB Output is correct
9 Correct 227 ms 26744 KB Output is correct
10 Correct 195 ms 23928 KB Output is correct
11 Correct 176 ms 23800 KB Output is correct
12 Correct 177 ms 23800 KB Output is correct
13 Correct 181 ms 23672 KB Output is correct
14 Correct 156 ms 23160 KB Output is correct
15 Correct 175 ms 22520 KB Output is correct
16 Correct 93 ms 19896 KB Output is correct
17 Correct 191 ms 24304 KB Output is correct
18 Correct 136 ms 24304 KB Output is correct
19 Correct 129 ms 24536 KB Output is correct
20 Correct 153 ms 24284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9856 KB Output is correct
2 Correct 35 ms 9864 KB Output is correct
3 Incorrect 10 ms 9856 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 184 ms 23912 KB Output is correct
2 Correct 191 ms 23628 KB Output is correct
3 Incorrect 197 ms 22884 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9728 KB Output is correct
2 Correct 11 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 9 ms 9728 KB Output is correct
5 Correct 10 ms 9756 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Incorrect 11 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 9728 KB Output is correct
2 Correct 11 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 9 ms 9728 KB Output is correct
5 Correct 10 ms 9756 KB Output is correct
6 Correct 10 ms 9728 KB Output is correct
7 Incorrect 11 ms 9728 KB Output isn't correct
8 Halted 0 ms 0 KB -