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<cstdio> #include<cstring> #include<stack> #include<algorithm> using namespace std; #define DOTMAX 5001 #define EDGEMAX 10001 #define min(a,b) ( (a)<(b)?(a):(b) ) stack<int>sta; struct node { int t; node *next; }dotset[EDGEMAX*2]; node hash[DOTMAX]; int visit[DOTMAX]; int low[DOTMAX]; int ID[DOTMAX]; int dfsn[DOTMAX]; int cont=0; node *Newnode() { node *p; p=&dotset[cont]; cont++; return p; } void init(int n) { while(!sta.empty()) { sta.pop(); } cont=0; int i; for(i=0;i<=n;i++) { hash[i].next=NULL; hash[i].t=-1; } } bool check(int a,int b) { node *p; for(p=hash[a].next;p!=NULL;p=p->next) { if(p->t==b) return false; } return true; } void AddNode(int a,int b) { node *p; node *q; if(check(a,b)) { q=&hash[a]; p=Newnode(); p->t=b; p->next=q->next; q->next=p; q=&hash[b]; p=Newnode(); p->t=a; p->next=q->next; q->next=p; } } int gcc=0; int cnt=0; void dfs(int u,int father) { ++cnt; dfsn[u]=cnt;low[u]=cnt;visit[u]=1; sta.push(u); node *p; for(p=hash[u].next;p!=NULL;p=p->next) { int v=p->t; if(v==father) continue; if(!visit[v]) { dfs(v,u); low[u]=min(low[u],low[v]); if(low[v]<=dfsn[u]) return ; if(low[v]>dfsn[u]) { gcc++; while(sta.top()!=p->t) { ID[sta.top()]=gcc; sta.pop(); } } ID[p->t]=gcc; sta.pop(); } else if(u!=v) { low[u]=min(low[u],dfsn[v]); } } } int main() { int n,m; int a,b; int i; scanf("%d%d",&n,&m); init(n); memset(low,0,sizeof(low)); memset(ID,0,sizeof(ID)); memset(visit,0,sizeof(visit)); gcc=0; cnt=0; AddNode(0,1); for(i=1;i<=m;i++) { scanf("%d%d",&a,&b); AddNode(a,b); } int degree[DOTMAX]; memset(degree,0,sizeof(degree)); dfs(0,-1); int res=0; node *p; for(i=1;i<=n;i++) { for(p=hash[i].next;p!=NULL;p=p->next) { if(ID[i]!=ID[p->t]&&p->t!=0) degree[ID[i]]++; } } for(i=1;i<=gcc;i++) { if(degree[i]==1) res++; } printf("%d\n",(res+1)/2); return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator