#include <bits/stdc++.h>
#define S 103
using namespace std;
int dirX[] = {1, 0, -1, 0};
int dirY[] = {0, 1, 0, -1};
int Equidivisions[S][S], n, cnt, r;
void dfs(int i, int j){
if(i < 1 || j < 1 || i > n || j > n || Equidivisions[i][j] != r)return;
cnt++;
Equidivisions[i][j] = S;
for(int z = 0; z < 4; z++){
int px = i+dirX[z];
int py = j+dirY[z];
dfs(px, py);
}
}
int main(){
while(cin >> n){
if(!n)return 0;
memset(Equidivisions, 0, sizeof(Equidivisions));
string inp;
int x, y;
getchar();
for(int i = 1; i < n; i++){
getline(cin, inp);
istringstream cinn(inp);
while(cinn >> x){
cinn >> y;
Equidivisions[x][y] = i;
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cnt = 0;
if(Equidivisions[i][j] != S){
ans++;
r = Equidivisions[i][j];
dfs(i, j);
if(cnt == n)ans--;
}
}
}
puts((!ans)?"good":"wrong");
}
return 0;
}
#define S 103
using namespace std;
int dirX[] = {1, 0, -1, 0};
int dirY[] = {0, 1, 0, -1};
int Equidivisions[S][S], n, cnt, r;
void dfs(int i, int j){
if(i < 1 || j < 1 || i > n || j > n || Equidivisions[i][j] != r)return;
cnt++;
Equidivisions[i][j] = S;
for(int z = 0; z < 4; z++){
int px = i+dirX[z];
int py = j+dirY[z];
dfs(px, py);
}
}
int main(){
while(cin >> n){
if(!n)return 0;
memset(Equidivisions, 0, sizeof(Equidivisions));
string inp;
int x, y;
getchar();
for(int i = 1; i < n; i++){
getline(cin, inp);
istringstream cinn(inp);
while(cinn >> x){
cinn >> y;
Equidivisions[x][y] = i;
}
}
int ans = 0;
for(int i = 1; i <= n; i++){
for(int j = 1; j <= n; j++){
cnt = 0;
if(Equidivisions[i][j] != S){
ans++;
r = Equidivisions[i][j];
dfs(i, j);
if(cnt == n)ans--;
}
}
}
puts((!ans)?"good":"wrong");
}
return 0;
}
No comments:
Post a Comment