제출 #103640

#제출 시각아이디문제언어결과실행 시간메모리
103640zubec철인 이종 경기 (APIO18_duathlon)C++14
23 / 100
1163 ms1049600 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const int N = 100100; int n, m; vector <int> g[N]; ll sz[N]; ll ans = 0; bool used[N]; void dfs(int v, int p){ sz[v] = 1; used[v] = 1; for (int i = 0; i < g[v].size(); i++){ int to = g[v][i]; if (to == p) continue; dfs(to, v); sz[v] += sz[to]; } } void dfs2(int v, int p, int n){ ll cursum = n-sz[v]; for (int i = 0; i < g[v].size(); i++){ int to = g[v][i]; if (to == p) continue; dfs2(to, v, n); ans += cursum*sz[to]*2; cursum += sz[to]; } } int main(){ ios_base::sync_with_stdio(0);cin.tie(0); //freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout); cin >> n >> m; for (int i = 1; i <= m; i++){ int u, v; cin >> u >> v; g[u].push_back(v); g[v].push_back(u); } for (int i = 1; i <= n; i++){ if (!used[i]){ dfs(i, 0); dfs2(i, 0, sz[i]); } } cout << ans; } /** 4 3 1 2 2 3 3 4 5 4 1 2 3 4 4 5 4 1 */

컴파일 시 표준 에러 (stderr) 메시지

count_triplets.cpp: In function 'void dfs(int, int)':
count_triplets.cpp:21:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++){
                     ~~^~~~~~~~~~~~~
count_triplets.cpp: In function 'void dfs2(int, int, int)':
count_triplets.cpp:31:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < g[v].size(); i++){
                     ~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...