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<map> #include<set> #include<cmath> #include<stack> #include<queue> #include<cstdio> #include<string> #include<vector> #include<cstring> #include<iomanip> #include<sstream> #include<iostream> #include<algorithm> #define INF 0x3f3f3f3f #define ls l,m,rt<<1 #define rs m+1,r,rt<<1|1 //#define ll __int64 //#define int ll typedef long long ll; typedef unsigned long long ull; const int MAXN=2e5+10; const int MOD=1e9+7; const double eps=1e-6; const double finf=1e10; using namespace std; template<class T>inline void read(T &res) { char c;T flag=1; while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0'; while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag; } //-------------------------------------------// int n,m,dfcnt,num,dfn[MAXN],low[MAXN],con[MAXN],head[MAXN],ins[MAXN]; stack<int> s; struct eddges { int to,next; }e[MAXN]; void tarjan(int u,int f) { dfn[u]=low[u]=++dfcnt; s.push(u); ins[u]=1; bool flag=0; for(int i=head[u];~i;i=e[i].next) { int v=e[i].to; if(v==f&&!flag){flag=1;continue;} if(!dfn[v]) { tarjan(v,u); low[u]=min(low[u],low[v]); } else if(ins[v])low[u]=min(low[u],dfn[v]); } if(dfn[u]==low[u]) { num++; int t; do { t=s.top(); s.pop(); con[t]=num; ins[t]=0; }while(t!=u); } } int counter; void add(int u,int v) { e[counter].to=v; e[counter].next=head[u]; head[u]=counter++; } int deg[MAXN],mu[MAXN],mv[MAXN]; int main() { //freopen("input.txt","r",stdin); scanf("%d%d",&n,&m); memset(head,-1,sizeof head); for(int i=0;i<m;++i) { int u,v; read(u);read(v); add(u,v); add(v,u); mu[i]=u; mv[i]=v; } for(int i=1;i<=n;++i) if(!dfn[i])tarjan(i,-1); int ans=0; for(int i=0;i<m;++i) { if(con[mu[i]]!=con[mv[i]]) { deg[mu[i]]++; deg[mv[i]]++; } } for(int i=1;i<=n;++i){ if(deg[i]==1)ans++;} printf("%d\n",(ans+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