답안 #790333

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
790333 2023-07-22T14:50:01 Z Dan4Life 철인 이종 경기 (APIO18_duathlon) C++17
23 / 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]+=(tot-sub[u])*(tot-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 746 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 746 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1120 ms 873864 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 2644 KB Output is correct
3 Correct 2 ms 2696 KB Output is correct
4 Correct 2 ms 2772 KB Output is correct
5 Correct 2 ms 2652 KB Output is correct
6 Correct 2 ms 2644 KB Output is correct
7 Correct 2 ms 2644 KB Output is correct
8 Correct 2 ms 2644 KB Output is correct
9 Correct 2 ms 2644 KB Output is correct
10 Correct 2 ms 2644 KB Output is correct
11 Correct 2 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 1 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 9432 KB Output is correct
2 Correct 59 ms 9420 KB Output is correct
3 Correct 66 ms 9500 KB Output is correct
4 Correct 59 ms 9484 KB Output is correct
5 Correct 60 ms 9376 KB Output is correct
6 Correct 81 ms 13120 KB Output is correct
7 Correct 109 ms 12256 KB Output is correct
8 Correct 67 ms 11504 KB Output is correct
9 Correct 94 ms 10800 KB Output is correct
10 Correct 60 ms 9492 KB Output is correct
11 Correct 62 ms 10688 KB Output is correct
12 Correct 61 ms 10760 KB Output is correct
13 Correct 64 ms 10700 KB Output is correct
14 Correct 54 ms 10412 KB Output is correct
15 Correct 48 ms 9968 KB Output is correct
16 Correct 31 ms 8684 KB Output is correct
17 Correct 63 ms 10916 KB Output is correct
18 Correct 52 ms 10872 KB Output is correct
19 Correct 60 ms 10928 KB Output is correct
20 Correct 50 ms 10912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 2 ms 2644 KB Output is correct
3 Runtime error 514 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 9428 KB Output is correct
2 Correct 60 ms 9380 KB Output is correct
3 Runtime error 570 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 746 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 746 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -