Submission #1120333

#TimeUsernameProblemLanguageResultExecution timeMemory
1120333matei__bDuathlon (APIO18_duathlon)C++17
0 / 100
1103 ms1048576 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define ll long long #define ull unsigned long long #define ld long double #define chad char #define mod 666'013 #define dim 100005 #define lim 1000000 #define BASE 31 #define NMAX 21'005 #define FOR(i,a,b) for(int i=(a); i<=(b); i++) #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> #define pii pair<int,int> #define pb push_back #define mp make_pair #define nr_biti __builtin_popcount using namespace __gnu_pbds; using namespace std; ifstream fin("b.in"); ofstream fout("b.out"); int t=1; ll n,m; vector<int> g[dim]; ll ans; ll sz[dim]; bool viz[dim]; void dfs(int nod,int daddy=0) { sz[nod]=1; viz[nod]=1; for(auto it:g[nod]) { if(it==daddy) continue; dfs(it,nod); sz[nod]+=sz[it]; } ans+=(2LL*(sz[nod]-1)*(n-sz[nod])); for(auto it:g[nod]) { if(it==daddy) continue; ans+=(sz[it]*(sz[nod]-1-sz[it])); } } void solve() { cin >> n >> m; for(int i=1; i<=m; i++) { int x,y; cin >> x >> y; g[x].pb(y); g[y].pb(x); } for(int i=1; i<=n; i++) { if(!viz[i]) dfs(i); } cout << ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); //cin >> t; while(t--) solve(); return 0; }
#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...