比赛 |
EYOI暨SBOI暑假快乐赛5th |
评测结果 |
AAAEEEEEEE |
题目名称 |
Sergey and Subway |
最终得分 |
30 |
用户昵称 |
遥时_彼方 |
运行时间 |
1.465 s |
代码语言 |
C++ |
内存使用 |
9.96 MiB |
提交时间 |
2022-06-29 11:52:57 |
显示代码纯文本
#include<bits/stdc++.h>
#define rep(x,y,z) for(int x=y;x<=z;x++)
#define drep(x,y,z) for(int x=y;x>=z;x--)
#define ull unsigned long long
#define ll long long
using namespace std;
inline int read()
{
int x=0;bool flag=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')flag=0;ch=getchar();}
while(ch>='0'&&ch<='9') {x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
if(flag) return x;
return ~(x-1);
}
inline void write(int x)
{
if(x<0) {x=~(x-1);putchar('-');}
if(x>9) write(x/10);
putchar(x%10+'0');
}
/////////////////////////
const int N=1e3+50;
int nc;
struct G
{
int ar;
int nx;
}a[N<<1];
int aj;
int hd[N];
inline void ADD(int x,int y)
{
a[++aj].ar=y;
a[aj].nx=hd[x];
hd[x]=aj;
}
int b[N][N];
ll ans;
inline void dfs(int x,int cl,int dep)
{
dep++;
for(int i=hd[cl];i;i=a[i].nx)
{
if(!b[x][a[i].ar])
{
b[x][a[i].ar]=1;
// cout<<ans<<endl;
ans+=(dep>>1)+(dep&1);
// cout<<ans<<","<<x<<" "<<a[i].ar<<" "<<dep<<"()"<<(dep>>1)+(dep&1)<<endl;
dfs(x,a[i].ar,dep);
}
}
}
int main()
{
freopen("Sergeyas.in","r",stdin);
freopen("Sergeyas.out","w",stdout);
nc=read();
int s1,s2;
rep(i,2,nc)
{
s1=read(),s2=read();
ADD(s1,s2);
ADD(s2,s1);
}
rep(i,1,nc) b[i][i]=1,dfs(i,i,0);
ans>>=1;
cout<<ans<<endl;
return 0;
}