比赛 |
20111111 |
评测结果 |
AAETTTTTEA |
题目名称 |
传话 |
最终得分 |
30 |
用户昵称 |
fanzeyi |
运行时间 |
0.000 s |
代码语言 |
C |
内存使用 |
0.00 MiB |
提交时间 |
2011-11-11 11:09:30 |
显示代码纯文本
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 1010
#define True 1
#define False -1
#define UNDEFINED 0
int n, m;
int status[MAX];
int map[MAX][MAX];
void PrintMap() {
int i, j;
for(i = 1; i <= n; i++) {
for(j = 1; j <= n; j++) {
printf("%d ", map[i][j]);
}
printf("\n");
}
}
int search(int now, int searchfor, int start) {
if(now == searchfor && !start) {
return 1;
}
int i;
int ans;
int flag = 1;
for(i = 1; i <= n; i++) {
if(map[now][i]) {
if(search(i, searchfor, 0)) {
return 1;
}
}
}
return 0;
}
int main(int argc, char const *argv[]) {
FILE *fin = fopen("messagez.in", "r");
FILE *fout = fopen("messagez.out", "w");
int flag;
int a, b;
int i, j;
memset(status, 0, sizeof(status));
fscanf(fin, "%d %d", &n, &m);
for(i = 0; i < m; i++) {
fscanf(fin, "%d %d", &a, &b);
map[a][b] = 1;
}
PrintMap();
for(i = 1; i <= n; i++) {
flag = 1;
for(j = 1; j <= n; j++) {
if(map[j][i]) {
flag = 0;
}
}
if(flag) {
status[i] = False;
}
}
for(i = 1; i <= n; i++) {
if(status[i] == UNDEFINED && search(i, i, 1)) {
status[i] = True;
}else{
status[i] = False;
}
}
for(i = 1; i <= n; i++) {
if(status[i] == True) {
fprintf(fout, "T\n");
}else{
fprintf(fout, "F\n");
}
}
return 0;
}