Submission #734857

#TimeUsernameProblemLanguageResultExecution timeMemory
734857keisuke6Duathlon (APIO18_duathlon)C++14
0 / 100
90 ms6660 KiB
#include <bits/stdc++.h> using namespace std; bool sub3(vector<vector<int>> &G){ for(int i=0;i<G.size();i++)if(G[i].size() > 2) return false; return true; } struct Unionfind{ vector<int> par, siz; //初期化 Unionfind(int n) : par(n,-1) , siz(n,1) {} int root(int x) { if(par[x] == -1) return x; else return par[x] = root(par[x]); } bool issame(int x,int y) { return root(x) == root(y); } bool unite(int x, int y){ x = root(x); y = root(y); if(x == y) return false; if(siz[x] < siz[y]) swap(x,y); par[y] = x; siz[x] += siz[y]; return true; } int size(int x) { return siz[root(x)]; } }; int main(){ int N,M; cin>>N>>M; vector<vector<int>> G(N); for(int i=0;i<M;i++){ int a,b; cin>>a>>b; a--; b--; G[a].push_back(b); G[b].push_back(a); } if(sub3(G)){ Unionfind uf(N); for(int i=0;i<N;i++){ for(int x:G[i]) uf.unite(i,x); } map<int,int> mm; for(int i=0;i<N;i++)for(int x:G[i]) mm[uf.root(x)]++; map<int,int> m; for(int i=0;i<N;i++) m[uf.root(i)]++; long long ans = 0; for(auto x:m){ int n = x.second; if(mm[x.first] == n) for(long long i=2;i<n;i++) ans += (i-1)*n*2; else for(long long i=2;i<n;i++) ans += (i-1)*(n-i)*2; } cout<<ans<<endl; return 0; } }

Compilation message (stderr)

count_triplets.cpp: In function 'bool sub3(std::vector<std::vector<int> >&)':
count_triplets.cpp:4:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    4 |   for(int i=0;i<G.size();i++)if(G[i].size() > 2) return false;
      |               ~^~~~~~~~~
#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...