/************************************
* 2012/06/26 *
* AOJ Volume11 1165 *
* Pablo Squarson's Headache *
* wrote crane *
*************************************/
#include<iostream>
using namespace std;
#define MAX_N 200
int field[MAX_N][2]; //[][0]->x [][1]->y
int dx[] = {-1, 0, 1, 0};
int dy[] = { 0, 1, 0, -1};
int main(){
int n;
while(cin >> n,n){
int x=0;int y=0;
int ni, di;
field[0][0] = 0;
field[0][1] = 0;
for(int i=1; i<n; i++){
cin >> ni >> di;
field[i][0] = field[ni][0] + dx[di];
field[i][1] = field[ni][1] + dy[di];
}
int xmin=10000, xmax=-10000;
int ymin=10000, ymax=-10000;
for(int i=0; i<n; i++){
if(field[i][0] < xmin) xmin =field[i][0];
if(field[i][0] > xmax) xmax =field[i][0];
if(field[i][1] < ymin) ymin =field[i][1];
if(field[i][1] > ymax) ymax =field[i][1];
}
x = xmax - xmin + 1;
y = ymax - ymin + 1;
cout << x << " "<< y << endl;;
}
return 0;
}
0 件のコメント:
コメントを投稿