제출 #1127852

#제출 시각아이디문제언어결과실행 시간메모리
1127852czauderna철인 이종 경기 (APIO18_duathlon)C++20
0 / 100
45 ms6212 KiB
// podzadanie na cykle i sciezki #include <bits/stdc++.h> using namespace std; using ll=long long; #define enl cerr<<'\n' #define onl cout<<'\n' #define sz(x) (int)(x).size() #define rep(a, b) for(int a=0; a<(b); a++) #define what(x) cerr<<(#x)<<": "<<(x)<<'\n' constexpr int N=1e5+6; vector<int> adj[N]; int gle[N]; bool used[N]; ll ans=0; void bfs(int z) { queue<pair<int, int>> q; int d=1; used[z]=true; q.push({z, 1}); while(!q.empty()) { auto [x, xd]=q.front(); d=max(d, xd); q.pop(); for(auto y:adj[x]) { if(!used[y]) { used[y]=true; q.push({y, xd+1}); } } } ans+=1LL*d*(d-1)*(d-2)/3; } int main() { cin.tie(nullptr)->sync_with_stdio(false); int n,m; cin>>n>>m; rep(i, m) { int x,y; cin>>x>>y; adj[x].push_back(y); adj[y].push_back(x); } for(int i=1; i<=n; i++) { if(sz(adj[i])==1 && !used[i]) { // poczatek sciezki bfs(i); } } for(int i=1; i<=n; i++) { if(sz(adj[i])==2 && !used[i]) { // poczatek cyklu bfs(i); } } cout<<ans;onl; }
#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...