답안 #790329

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790329 2023-07-22T14:47:19 Z Dan4Life 철인 이종 경기 (APIO18_duathlon) C++17
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ar = array<int,2>;
const int mxN = (int)1e5+10;
int n, m, ans, tot,VV[mxN],vis[mxN];
vector<int> adj[mxN];
int sub[mxN], totsq[mxN], xd=0;

void dfs(int s, int p){
	VV[s]=1; sub[s]=1; totsq[s]=0;
	for(auto u : adj[s]){
		if(u==p) continue;
		dfs(u,s); sub[s]+=sub[u];
		totsq[s]+=sub[u]*sub[u];
	}
}

void reroot(int s, int u){
	totsq[s]-=sub[u]*sub[u];
	totsq[u]+=(n-sub[u])*(n-sub[u]);
	sub[s]-=sub[u]; sub[u]+=sub[s];
	if(!vis[u]) ans+=(tot-1)*(tot-1)-totsq[u],vis[u]=1;
}

void dfs2(int s, int p){
	for(auto u : adj[s]){
		if(u==p) continue;
		reroot(s,u);
		dfs2(u,s);
		reroot(u,s);
	}
}

int32_t main() {
	cin >> n >> m;
	for(int i = 0; i < m; i++){
		int a, b; cin >> a >> b;
		adj[a].pb(b), adj[b].pb(a);
	}
	for(int i = 1; i <= n; i++)
		if(!VV[i]) dfs(i,-1), tot = sub[i], dfs2(i,-1); 
	cout << ans << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 419 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 419 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1099 ms 1027488 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2676 KB Output is correct
3 Correct 2 ms 2644 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2772 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2772 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Incorrect 2 ms 2644 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 9420 KB Output is correct
2 Correct 61 ms 9420 KB Output is correct
3 Correct 63 ms 9500 KB Output is correct
4 Correct 72 ms 9596 KB Output is correct
5 Correct 69 ms 9440 KB Output is correct
6 Correct 68 ms 13164 KB Output is correct
7 Correct 70 ms 12264 KB Output is correct
8 Correct 63 ms 11532 KB Output is correct
9 Correct 62 ms 10724 KB Output is correct
10 Incorrect 90 ms 9496 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Runtime error 420 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 9440 KB Output is correct
2 Correct 81 ms 9336 KB Output is correct
3 Runtime error 552 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 419 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 419 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -