Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
谁能帮我看看为什么WA,郁闷#include <iostream> #include <queue> #include <stdio.h> using namespace std; const int MAXX = 1002; const int inf = 100000000; struct point { int number; point * pnext; }; struct node { int nnumber; point * nnext; }; node map[MAXX]; bool mark[MAXX] = {0}; bool m[MAXX][MAXX]; void Init (node map[MAXX] , int n) { int i; for (i = 1 ; i <= n; ++i) { map[i].nnumber = i; map[i].nnext = NULL; } } bool Search(int b , int e) { int i; int j; queue<int> s; int k; point * p; p = map[b].nnext; mark[b] = 1; while (p) { /// cout << p -> number << " "; if(p->number == e) { return 1; } if(p->number != inf && !mark[p->number]) { s.push(p -> number); } p = p -> pnext; } while(s.size()) { k = s.front(); s.pop(); p = map[k].nnext; mark[k] = 1; while(p) { /// cout << p->number << " "; if(p->number == e) { return 1; } if(p->number != inf && !mark[p->number] ) { s.push(p -> number); } p = p -> pnext; } } return 0; } void Insert(int b , int e) { point *s = new point; s->number = e; s->pnext = map[b].nnext; map[b].nnext = s; } void Delet(int b , int e) { point *p = map[b].nnext; // point *q = NULL; if (p->number == e) { p->number = inf; } else { while(p && p ->pnext) { if (p->pnext ->number == e) { // q = p->pnext; p = p ->pnext->pnext; // delete q; break; } else { p = p -> pnext; } } } } int main() { int n; int connecte; int i; int j; // freopen("1.txt","r",stdin); while(cin >> n >> connecte) { memset(mark,0,sizeof(mark)); memset(m,0,sizeof(m)); char command; int b; int e; for (i = 1; i <= connecte ; ++i) { memset(mark,0,sizeof(mark)); cin >> command; scanf("%d%d",&b,&e); if (command == 'Q') { if (Search(b , e)) { printf("Y\n"); } else if (b == e) { printf("Y\n"); } else { printf("N\n"); } } if (command == 'I') { if (m[b][e] == 0 && b != e) { Insert(b,e); Insert(e,b); m[b][e] = 1; m[e][b] = 1; } } if (command == 'D') { if (m[b][e] != 0 && b != e) { Delet(b,e); Delet(e,b); m[b][e] = 0; m[e][b] = 0; } } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator