Submission #1013985

# Submission time Handle Problem Language Result Execution time Memory
1013985 2024-07-04T09:09:55 Z pcc Duathlon (APIO18_duathlon) C++17
31 / 100
79 ms 33860 KB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
const int mxn = 1e5+10;
vector<int> paths[mxn],tree[mxn*2];
int N,M;
bitset<mxn> vis;
ll ans = 0;

namespace TARJAN{
	int idx[mxn],low[mxn],gcnt,cnt;
	vector<int> st,gid[mxn];

	void dfs(int now,int par){
		st.push_back(now);
		low[now] = idx[now] = ++cnt;
		for(auto nxt:paths[now]){
			if(idx[nxt]){
				low[now] = min(low[now],idx[nxt]);
			}
			else{
				dfs(nxt,now);
				low[now] = min(low[now],low[nxt]);
				if(low[nxt] == idx[now]){
					gcnt++;
					int id = st.back();
					do{
						assert(!st.empty());
						id = st.back();st.pop_back();
						gid[id].push_back(gcnt);
						tree[gcnt+N].push_back(id);
						tree[id].push_back(gcnt+N);
					}while(id != nxt);
					gid[now].push_back(gcnt);
					tree[gcnt+N].push_back(now);
					tree[now].push_back(gcnt+N);
				}
			}

		}
		return;
	}

	void GO(){
		for(int i = 1;i<=N;i++){
			if(gid[i].empty())dfs(i,i);
		}
		return;
	}
}

namespace DP{
	int dp[mxn*2];
	bitset<mxn*2> vis;
	void dfs1(int now,int fa){
		if(now<=N)dp[now] = 1;
		else dp[now] = 0;
		vis[now] = true;
		for(auto nxt:tree[now]){
			if(nxt == fa)continue;
			dfs1(nxt,now);
			dp[now] += dp[nxt];
		}
		return;
	}
	void dfs2(int now,int fa,int sz){
		for(auto nxt:tree[now]){
			if(nxt == fa)continue;
			dfs2(nxt,now,sz);
		}
		if(now>N)return;
		ll sum = 0;
		for(auto nxt:tree[now]){
			if(nxt == fa)continue;
			ans += sum*dp[nxt]*2;
			sum += dp[nxt];
			ll ts = tree[nxt].size();
			ans += (ts-1)*(ts-2);
		}
		ll tmp = sz-dp[now];
		ans += sum*tmp*2;
		if(fa != now){
			ll ts = tree[fa].size();
			ans += (ts-1)*(ts-2);
		}
		return;
	}
	void GO(){
		for(int i = 1;i<=N;i++){
			if(vis[i])continue;
			dfs1(i,i);
			dfs2(i,i,dp[i]);
		}
	}
}

int main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>N>>M;
	for(int i = 0;i<M;i++){
		int a,b;
		cin>>a>>b;
		paths[a].push_back(b);
		paths[b].push_back(a);
	}
	TARJAN::GO();
	DP::GO();
	cout<<ans<<'\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 9848 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Incorrect 4 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 9848 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Incorrect 4 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 52 ms 33228 KB Output is correct
2 Correct 54 ms 33228 KB Output is correct
3 Correct 63 ms 30160 KB Output is correct
4 Correct 60 ms 31176 KB Output is correct
5 Correct 54 ms 27344 KB Output is correct
6 Correct 57 ms 29136 KB Output is correct
7 Correct 53 ms 26832 KB Output is correct
8 Correct 54 ms 27472 KB Output is correct
9 Correct 58 ms 25424 KB Output is correct
10 Correct 57 ms 25684 KB Output is correct
11 Correct 48 ms 23100 KB Output is correct
12 Correct 50 ms 22864 KB Output is correct
13 Correct 47 ms 22736 KB Output is correct
14 Correct 44 ms 22224 KB Output is correct
15 Correct 42 ms 20972 KB Output is correct
16 Correct 34 ms 20684 KB Output is correct
17 Correct 9 ms 11500 KB Output is correct
18 Correct 6 ms 11500 KB Output is correct
19 Correct 6 ms 11492 KB Output is correct
20 Correct 6 ms 11496 KB Output is correct
21 Correct 6 ms 11484 KB Output is correct
22 Correct 9 ms 11488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9892 KB Output is correct
4 Correct 5 ms 10076 KB Output is correct
5 Correct 5 ms 10076 KB Output is correct
6 Correct 5 ms 10036 KB Output is correct
7 Correct 5 ms 10076 KB Output is correct
8 Correct 5 ms 10076 KB Output is correct
9 Correct 4 ms 9892 KB Output is correct
10 Correct 5 ms 9816 KB Output is correct
11 Correct 5 ms 9820 KB Output is correct
12 Correct 4 ms 9796 KB Output is correct
13 Correct 5 ms 9820 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9980 KB Output is correct
17 Correct 5 ms 9820 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 5 ms 9820 KB Output is correct
20 Correct 4 ms 9912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 76 ms 25496 KB Output is correct
2 Correct 70 ms 25428 KB Output is correct
3 Correct 61 ms 25424 KB Output is correct
4 Correct 67 ms 25528 KB Output is correct
5 Correct 67 ms 25516 KB Output is correct
6 Correct 73 ms 33860 KB Output is correct
7 Correct 72 ms 30828 KB Output is correct
8 Correct 72 ms 29348 KB Output is correct
9 Correct 79 ms 27948 KB Output is correct
10 Correct 64 ms 25424 KB Output is correct
11 Correct 61 ms 25424 KB Output is correct
12 Correct 56 ms 25424 KB Output is correct
13 Correct 70 ms 25424 KB Output is correct
14 Correct 60 ms 24656 KB Output is correct
15 Correct 70 ms 23888 KB Output is correct
16 Correct 34 ms 20432 KB Output is correct
17 Correct 51 ms 26252 KB Output is correct
18 Correct 50 ms 26184 KB Output is correct
19 Correct 49 ms 26568 KB Output is correct
20 Correct 47 ms 26192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9820 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Incorrect 5 ms 9816 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 63 ms 25424 KB Output is correct
2 Correct 71 ms 25384 KB Output is correct
3 Incorrect 78 ms 24916 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 9848 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Incorrect 4 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 10072 KB Output is correct
2 Correct 4 ms 9848 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Incorrect 4 ms 9820 KB Output isn't correct
8 Halted 0 ms 0 KB -