답안 #982491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
982491 2024-05-14T10:04:23 Z MuhammadSaram 철인 이종 경기 (APIO18_duathlon) C++17
31 / 100
51 ms 16836 KB
/********************* بسم الله الرحمن الرحيم ***********************/
 /******************** ٱلْحَمْدُ لِلَّٰهِ رَبِّ ٱلْعَالَمِينَ *************************/
/******************* Prophet Muhammad صلى الله عليه وسلم ************/
   /*********************** وَقُل رَّبِّ زِدْنِي عِلْمًا **************************/

#ifdef ONLINE_JUDGE
	#pragma GCC optimize("Ofast")
	#pragma GCC optimize("O3,unroll-loops")
	#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#else

#endif

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl '\n'
#define in binary_search
#define ll long long
#define ld long double
#define Hey ios::sync_with_stdio(false);
#define Welcome cin.tie(NULL), cout.tie(NULL);
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()

const int M = 1e5 + 1;

vector<int> nei[M];
bool vis[M];
int cnt,ans,subt[M],deg[M],dep[M];
vector<int> cc;

void dfs(int u)
{
	vis[u]=true;
	subt[u]=1;
	cnt++;
	cc.push_back(u);
	for (int i:nei[u])
		if (!vis[i])
		{
			dfs(i);
			subt[u]+=subt[i];
		}
}

void dfs1(int u)
{
	vis[u]=true;
	for (int i:nei[u])
		if (!vis[i])
		{
			ans+=(subt[i]-1)*(cnt-subt[i]-1)*2;
			ans+=cnt-2;
			dep[i]=dep[u]+1;
			dfs1(i);
		}
		else if(dep[i]<dep[u] and dep[u]-1!=dep[i])
		{
			int cyc=dep[u]-dep[i]+1;
			int x=cnt-subt[i];
			ans+=cyc*(cyc-2)*(cyc-1)/3*2;
			ans+=x*(cyc-1)*(cyc-2);
			ans+=(subt[u]-1)*(cyc-1)*(cyc-2);
		}
}

void solve()
{
	int n,m;
	cin>>n>>m;
	for (int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		nei[u].push_back(v);
		nei[v].push_back(u);
		deg[u]++;
		deg[v]++;
	}
	for (int i=1;i<=n;i++)
	{
		if (!vis[i])
		{
			cc.clear();
			cnt=0;
			dfs(i);
			for (int j:cc)
				vis[j]=false;
			dfs1(i);
		}
	}
	cout<<ans<<endl;
}

signed main()
{
	Hey! Welcome // S'up
	
	int t = 1;
	cout<<fixed<<setprecision(20);
	while (t--)
		solve();
	
	return 0;
}

Compilation message

count_triplets.cpp: In function 'int main()':
count_triplets.cpp:99:5: warning: value computed is not used [-Wunused-value]
   99 |  Hey! Welcome // S'up
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 16836 KB Output is correct
2 Correct 40 ms 16584 KB Output is correct
3 Correct 39 ms 13268 KB Output is correct
4 Correct 35 ms 14796 KB Output is correct
5 Correct 35 ms 11984 KB Output is correct
6 Correct 35 ms 12240 KB Output is correct
7 Correct 34 ms 10960 KB Output is correct
8 Correct 33 ms 11720 KB Output is correct
9 Correct 33 ms 10332 KB Output is correct
10 Correct 32 ms 10956 KB Output is correct
11 Correct 24 ms 9296 KB Output is correct
12 Correct 25 ms 9080 KB Output is correct
13 Correct 29 ms 9304 KB Output is correct
14 Correct 22 ms 9052 KB Output is correct
15 Correct 17 ms 8276 KB Output is correct
16 Correct 18 ms 8412 KB Output is correct
17 Correct 2 ms 4956 KB Output is correct
18 Correct 2 ms 4956 KB Output is correct
19 Correct 2 ms 4956 KB Output is correct
20 Correct 2 ms 4956 KB Output is correct
21 Correct 2 ms 4956 KB Output is correct
22 Correct 2 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 1 ms 4956 KB Output is correct
5 Correct 1 ms 4956 KB Output is correct
6 Correct 1 ms 4956 KB Output is correct
7 Correct 1 ms 5208 KB Output is correct
8 Correct 1 ms 5168 KB Output is correct
9 Correct 1 ms 4952 KB Output is correct
10 Correct 2 ms 4956 KB Output is correct
11 Correct 1 ms 4952 KB Output is correct
12 Correct 1 ms 4956 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 1 ms 4956 KB Output is correct
15 Correct 1 ms 4956 KB Output is correct
16 Correct 1 ms 5084 KB Output is correct
17 Correct 1 ms 4952 KB Output is correct
18 Correct 1 ms 4956 KB Output is correct
19 Correct 1 ms 4956 KB Output is correct
20 Correct 1 ms 4956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 30 ms 11208 KB Output is correct
2 Correct 31 ms 11216 KB Output is correct
3 Correct 29 ms 10956 KB Output is correct
4 Correct 30 ms 11220 KB Output is correct
5 Correct 30 ms 11208 KB Output is correct
6 Correct 35 ms 13828 KB Output is correct
7 Correct 35 ms 13260 KB Output is correct
8 Correct 34 ms 12640 KB Output is correct
9 Correct 34 ms 12236 KB Output is correct
10 Correct 29 ms 10712 KB Output is correct
11 Correct 30 ms 11212 KB Output is correct
12 Correct 30 ms 10592 KB Output is correct
13 Correct 29 ms 10444 KB Output is correct
14 Correct 27 ms 9904 KB Output is correct
15 Correct 23 ms 9300 KB Output is correct
16 Correct 16 ms 8156 KB Output is correct
17 Correct 23 ms 11728 KB Output is correct
18 Correct 22 ms 11212 KB Output is correct
19 Correct 21 ms 11324 KB Output is correct
20 Correct 26 ms 11368 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Incorrect 2 ms 4952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 11212 KB Output is correct
2 Correct 34 ms 10964 KB Output is correct
3 Incorrect 39 ms 11664 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4956 KB Output isn't correct
2 Halted 0 ms 0 KB -