# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
104525 | tc_abd | Duathlon (APIO18_duathlon) | C++14 | 169 ms | 10972 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int n,m,curr=1;
int psum[100009];
bool done[100009];
vector < int > v[100009];
void dfs(int node){
psum[node] = curr++;
done[node] = 1;
for(int i=0;i<v[node].size();i++){
int u = v[node][i];
if(!done[u]) dfs(u);
}
}
int main(){
cin>>n>>m;
for(int i=0;i<m;i++){
int a,b;
cin>>a>>b;
a--;b--;
v[a].push_back(b);
v[b].push_back(a);
}
int x = 0,y = 0;
bool z = 0;
for(int i=0;i<n;i++){
if(v[i].size() == 1 && z == 0){x = i;z=1;continue;}
if(v[i].size() == 1 && z == 1){y = i;break;}
}
dfs(x);
int ans = 0;
for(int i=0;i<n;i++){
int x = psum[y] - psum[i];
int y = psum[i] - 1;
if(x != 0) ans += ((x-1)*x)/2;
if(y != 0) ans += ((y-1)*y)/2;
}
cout<<ans<<endl;
}
Compilation message (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... |