| ||||||||||
| 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 | |||||||||
Output Limit Exceed!?那位大虾帮忙分析一下阿……#include<stdio.h>
#include<iostream>
using namespace std;
struct node
{
int v;
bool visit;
};
vector<struct node>*g;
void dfs(int v)
{
for(vector<struct node>::iterator itr = g[v].begin();itr!=g[v].end();itr++)
{
if(itr->visit)continue;
itr->visit = true;
dfs(itr->v);
}
cout<<v<<endl;
}
int main()
{
freopen("in.txt","r",stdin);
int m,n,i,j,k;
cin>>m>>n;
g = new vector<struct node>[m+1];
struct node temp;
temp.visit = false;
for(i = 0;i<n;i++)
{
cin>>j>>k;
temp.v = j;
g[k].push_back(temp);
temp.v = k;
g[j].push_back(temp);
}
dfs(1);
return 0;
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator