Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么是RuntimeError?

Posted by 200842128 at 2012-01-09 08:58:13 on Problem 1144
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<set>
using namespace std;

const int Max = 510;
vector<int> g[Max];
set<int> art;

int n;
int seqNum;
int pre[Max];
int low[Max];
int artNum;

void input()
{
	int head, tail;
	char c;

	while(true)
	{
		scanf("%d%c", &head, &c);
		if(!head) break;

		while(true)
		{	
			scanf("%d%c", &tail, &c);
			g[head].push_back(tail);
			g[tail].push_back(head);

			if(c == '\n') break;
		}
	}
}


void dfs(int v)
{
	int min;
	min = pre[v] = ++seqNum;
	for(int i=0; i<g[v].size(); i++)
	{
		int child = g[v][i];
		if(!pre[child])
		{
			dfs(child);

			if(low[child] < min) 
				min = low[child];
			if(low[child] >= pre[v]) 
				art.insert(v);
		}
		else
		{
			if(min > pre[child]) min = pre[child];
		}
	}

	low[v] = min;
}

void articulation()
{
	artNum = 0;
	seqNum = 1;
	pre[1] = 1;
	for(int i=2; i<=n; i++) pre[i] = 0;

	dfs(g[1][0]);

	artNum = art.size();
	if(seqNum < n) 
	{
		artNum ++;
		for(int i=0; i<=g[1].size(); ++i)
			if(!pre[g[1][i]])
				dfs(g[1][i]);
	}
}

int main()
{	
	while(cin >> n && n)
	{
		input();
		if(n == 1)  printf("0\n");
		else
		{
			articulation();
			art.clear();
			printf("%d\n", artNum);
			for(int i=0; i<Max; i++) g[i].clear();
		}
	}
	system("pause");
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator