# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
106374 | Hideo | 철인 이종 경기 (APIO18_duathlon) | C++14 | 205 ms | 15480 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
#define vi vector < int >
#define pii pair < int, int >
const int N = 2e5 + 7;
const int INF = 1e9 + 7;
int sz[N];
int n, m;
int ans;
vi g[N];
int asd;
int as[N];
void dfs (int v = 1, int p = 0){
sz[v] = 1;
as[v] = asd;
for (int to : g[v]){
if (!sz[to]){
dfs(to, v);
sz[v] += sz[to];
}
}
}
main(){
cin >> n >> m;
for (int i = 1; i <= m; i++){
int a, b;
scanf("%lld%lld", &a, &b);
g[a].pb(b);
g[b].pb(a);
}
for (int i = 1; i <= n; i++) {
if (!sz[i]) {
asd = i;
dfs(i);
ans -= sz[i] * (sz[i] - 1) / 2;
}
}
for (int i = 1; i <= n; i++) {
ans += (sz[i] * (sz[as[i]] - sz[i]));
}
cout << ans * 2;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |