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 |
Hawk大哥,我这个O(m)的复杂度的C++程序,G++ RE, C++ TLE,真的搞不明白了啦。。。。。。#include <iostream> #include <list> using namespace std; typedef struct vertc { int dest; int visit; }vert; typedef list<vert> vlist; typedef vlist::iterator vptr; void dfs(vlist *nodes, int nr) { for(vptr itr = nodes[nr].begin(); itr != nodes[nr].end(); itr ++) { if( itr->visit ) continue; itr->visit = 1; dfs(nodes, itr->dest); } printf("%d\n", nr + 1); } int main() { int m,n,a,b,i; vert nvt; vlist *nodes; scanf("%d%d", &n, &m); nodes = new vlist[n]; nvt.visit = 0; for(i = 0; i < m; i ++) { scanf("%d%d", &a, &b); a--, b--; nvt.dest = b; nodes[a].push_back(nvt); nvt.dest = a; nodes[b].push_back(nvt); } dfs(nodes, 0); delete []nodes; return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator