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

帮忙找一组能卡掉这个代码的数据

Posted by the_brothers_four at 2015-08-12 21:28:11 on Problem 2942
#include<cstdio>
#include<stack>
#include<cstring>
using namespace std;
const int N=1005, M=1e6;
struct edge{
	int to, nt, id;
}E[M]; 
int head[N], id; 
bool g[N][N];
void add(int u, int v){
	E[id]=(edge){v, head[u], 0}; head[u]=id++;
	E[id]=(edge){u, head[v], 0}; head[v]=id++;
}

bool ok[N];
bool label(int u, int id){
	ok[u]=true;
	for(int i=head[u]; ~i; i=E[i].nt){
		if(E[i].id!=id) continue;
		int &v=E[i].to;
		if(!ok[v]) label(v, id);
	}
}

int col[N];
bool color(int u, int c, int id){
	col[u]=c;
	for(int i=head[u]; ~i; i=E[i].nt){
		if(E[i].id!=id) continue;
		int &v=E[i].to;
		if(!col[v]&&!color(v, -c, id)) return false;
		if(col[v]==col[u]) return false; 
	}
	return true;
}

stack<int> st;
int low[N], dfn[N], ts;
void dfs(int u, int f){
	low[u]=dfn[u]=++ts;
	for(int i=head[u]; ~i; i=E[i].nt){
		int &v=E[i].to;
		if(!dfn[v]){
			st.push(i);
			dfs(v, i>>1);
			low[u]=min(low[u], low[v]);
			if(low[v]>=dfn[u]){
				++id;
				for(;;){
					int top=st.top(); st.pop();
					E[top].id=id;
					if(top==i) break;
				}
				memset(col, 0, sizeof(col));
				if(!color(u, 1, id)){
					label(u, id);
				}
			}
		}
		else if(i>>1!=f&&dfn[u]>dfn[v]){
			st.push(i);
			low[u]=min(low[u], dfn[v]);
		}
	}
}  

int main(){
	//freopen("in", "r", stdin);
	int n, m, u, v;
	
	while(scanf("%d%d", &n, &m), n){
		memset(head, -1, sizeof(head));
		memset(g, 0, sizeof(g));
		id=0;
		while(m--){
			scanf("%d%d", &u, &v);
			g[u][v]=g[v][u]=true;
		}
		for(int i=1; i<=n; i++)for(int j=i+1; j<=n; j++){
			if(!g[i][j]) add(i, j);
		}
		id=ts=0;
		memset(dfn, 0, sizeof(dfn));
		memset(ok, 0, sizeof(ok));
		for(int i=1; i<=n; i++) if(!dfn[i]) dfs(i, -1);
		int res=0;
		for(int i=1; i<=n; i++){
			if(!ok[i]) res++;
		}
		printf("%d\n", res);
	}
	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