//
//                       _oo0oo_
//                      o8888888o
//                      88" . "88
//                      (| -_- |)
//                      0\  =  /0
//                    ___/`---'\___
//                  .' \\|     |// '.
//                 / \\|||  :  |||// \
//                / _||||| -:- |||||- \
//               |   | \\\  -  /// |   |
//               | \_|  ''\---/''  |_/ |
//               \  .-\__  '-'  ___/-. /
//             ___'. .'  /--.--\  `. .'___
//          ."" '<  `.___\_<|>_/___.' >' "".
//         | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//         \  \ `_.   \_ __\ /__ _/   .-` /  /
//     =====`-.____`.___ \_____/___.-`___.-'=====
//                       `=---='

#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define ll long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
#define lc (x<<1)
#define rc ((x<<1)|1)
using namespace std;
V<int> v[200005];
V<P<int,int> > g[200005];
int d[200005],ma[200005],it[200005],pl[200005];
void dfs(int x,int y){
	for(auto u:v[x])if(u!=y)g[x].PB(MP(pl[u],u));
	sort(ALL(g[x]));
	ma[x]=d[x]+it[x];
	for(auto u:g[x])if(u.S!=y){
		it[u.S]=ma[x]+1-d[x];
		d[u.S]=d[x]+1;
		dfs(u.S,x);
		gmax(ma[x],ma[u.S]);
	}
}
int siz[200005],in[200005];
int n;
void get(int x,int y){
	siz[x]=1;pl[x]=0;
	for(auto u:v[x])if(u!=y){
		d[u]=d[x]+1;
		get(u,x);
		gmax(pl[x],pl[u]);
		siz[x]+=siz[u];
		gmax(in[x],siz[u]);
	}
	pl[x]++;
	gmax(in[x],n-siz[x]);
}
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	FOR(i,2,n){
		int x,y;
		cin>>x>>y;
		v[x].PB(y);
		v[y].PB(x);
	}
	get(1,-1);
	int st=1;
	FOR(i,2,n){
		if(d[i]>d[st])st=i;
	}
	get(st,-1);
	it[st]=1;
	dfs(st,-1);
	FOR(i,1,n)cout<<it[i]<<' ';
	RE 0;
}









#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,m,cnt;
struct Obstacle {
	int x,y;
	bool operator<(const Obstacle rhs) const {
		if(x==rhs.x) {
			return y<rhs.y;
		}
		return x<rhs.x;
	}
}a[200005];
int lenn[200005];//Maximum x you can go with y=i
int lenm[200005];//Maximum y you can go with x=i
int tr[200005];
bool vis[200005];
ll ans;

int lowbit(int x) {
	return x&-x;
}

void add(int pos,int num) {
	for(int i=pos;i<=m;i+=lowbit(i)) {
		tr[i]+=num;
	}
}

int sum(int pos) {
	int res=0;
	for(int i=pos;i>=1;i-=lowbit(i)) {
		res+=tr[i];
	}
	return res;
}

vector<int> ob[200005];

int main() {
	scanf("%d %d %d",&n,&m,&cnt);
	for(int i=1;i<=n;i++) {
		lenm[i]=m;
	}
	for(int i=1;i<=m;i++) {
		lenn[i]=n;
	}
	for(int i=1;i<=cnt;i++) {
		scanf("%d %d",&a[i].x,&a[i].y);
		ob[a[i].x].push_back(a[i].y);
		lenm[a[i].x]=min(lenm[a[i].x],a[i].y-1);
		lenn[a[i].y]=min(lenn[a[i].y],a[i].x-1);
	}
	for(int i=1;i<=lenm[1];i++) {
		ans+=lenn[i];
	}
	for(int i=lenm[1]+1;i<=m;i++) {
		vis[i]=1;
		add(i,1);
	}
	for(int i=2;i<=lenn[1];i++) {
		ans+=sum(lenm[i]);
		for(int j=0;j<ob[i].size();j++) {
			if(!vis[ob[i][j]]) {
				vis[ob[i][j]]=1;
				add(ob[i][j],1);
			}
		}
	}
	printf("%lld",ans);
	return 0;
}