답안 #927763

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927763 2024-02-15T10:05:29 Z TAhmed33 철인 이종 경기 (APIO18_duathlon) C++
0 / 100
1000 ms 1048576 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int n;
vector <int> adj[300001];
int sze[300001];
bool vis[300001];
void calc (int pos, int par) {
  	vis[pos] = 1;
	for (auto j : adj[pos]) {
		if (j == par) continue;
		calc(j, pos);
		sze[pos] += sze[j];
	}
	sze[pos]++;
}
int ans = 0;
void dfs (int pos, int par) {
  	vis[pos] = 1;
    ans += 2 * (n - sze[pos]) * (sze[pos] - 1);
    int cur = 0;
    for (auto j : adj[pos]) {
        if (j == par) continue;
        ans += 2 * sze[j] * cur;
        cur += sze[j];
        dfs(j, pos);
    }
}
signed main () {
    cin >> n; int m; cin >> m; 
    for (int i = 1; i <= m; i++) {
	    int a, b;
	    cin >> a >> b;
	    adj[a].push_back(b);
	    adj[b].push_back(a);
    }
    for (int i = 1; i <= n; i++) if (!vis[i]) calc(i, -1);
    memset(vis, 0, sizeof(vis));
  	for (int i = 1; i <= n; i++) if (!vis[i]) dfs(i, -1);
  	cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 625 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 625 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1107 ms 1044592 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 10072 KB Output is correct
2 Correct 3 ms 10076 KB Output is correct
3 Correct 2 ms 10076 KB Output is correct
4 Correct 3 ms 10076 KB Output is correct
5 Correct 3 ms 10076 KB Output is correct
6 Correct 3 ms 10076 KB Output is correct
7 Correct 3 ms 9940 KB Output is correct
8 Correct 3 ms 10076 KB Output is correct
9 Correct 3 ms 10076 KB Output is correct
10 Incorrect 3 ms 10328 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 13712 KB Output is correct
2 Correct 59 ms 13760 KB Output is correct
3 Correct 75 ms 13840 KB Output is correct
4 Correct 58 ms 13772 KB Output is correct
5 Correct 65 ms 13596 KB Output is correct
6 Correct 63 ms 16448 KB Output is correct
7 Correct 64 ms 15984 KB Output is correct
8 Correct 83 ms 15444 KB Output is correct
9 Correct 80 ms 14752 KB Output is correct
10 Incorrect 90 ms 13652 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 10072 KB Output is correct
2 Correct 3 ms 10328 KB Output is correct
3 Runtime error 684 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 13644 KB Output is correct
2 Correct 57 ms 13636 KB Output is correct
3 Runtime error 766 ms 1048576 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 625 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 625 ms 1048576 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -