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> using namespace std; int n, m, l; int edge[50000], path[500000]; int findx[10000], findy[10000]; struct node { int x, y, p; } edgex[50000], edgey[50000]; bool cmpx(node a, node b) { if (a.x < b.x) return true; else return false; } bool cmpy(node a, node b) { if (a.y < b.y) return true; else return false; } void make(int k) { int i; for (i = findx[k]; i < m; i ++) { if (edgex[i].x != k) break; while (edge[edgex[i].p] > 0) { edge[edgex[i].p] --; make(edgex[i].y); } } for (i = findy[k]; i < m; i ++) { if (edgey[i].y != k) break; while (edge[edgey[i].p] > 0) { edge[edgey[i].p] --; make(edgey[i].x); } } path[l] = k; l ++; } int main() { int i, a, b; while (scanf("%d%d", &n, &m) != -1) { for (i = 0; i < m; i ++) { scanf("%d%d", &a, &b); edgex[i].x = a - 1; edgex[i].y = b - 1; edgex[i].p = i; edgey[i].x = a - 1; edgey[i].y = b - 1; edgey[i].p = i; edge[i] = 2; } sort(edgex, edgex + m, cmpx); sort(edgey, edgey + m, cmpy); memset(findx, 0, sizeof(findx)); memset(findy, 0, sizeof(findy)); for (i = 0; i < m; i ++) if ((i == 0) || (edgex[i].x != edgex[i - 1].x)) findx[edgex[i].x] = i; for (i = 0; i < m; i ++) if ((i == 0) || (edgey[i].y != edgey[i - 1].y)) findy[edgey[i].y] = i; l = 0; make(0); for (i = l - 1; i >= 0; i --) printf("%d\n", path[i] + 1); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator