[51nod1299]*逃离

到现在还是不会写系列,直接贴题解了。

http://www.51nod.com/question/index.html#!questionId=1157

 #include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
#define ll long long
#define ui unsigned int
using namespace std;
const int maxn=;
struct zs{int too,pre;}e[maxn<<];int tot,last[maxn];
int zt[maxn],deg[maxn];
int i,j,k,n,m,ans;
bool gg[maxn],GG; int ra,fh;char rx;
inline int read(){
rx=getchar(),ra=,fh=;
while((rx<''||rx>'')&&rx!='-')rx=getchar();
if(rx=='-')fh=-,rx=getchar();
while(rx>=''&&rx<='')ra*=,ra+=rx-,rx=getchar();return ra*fh;
}
inline void insert(int a,int b){
deg[a]++,deg[b]++;
e[++tot].too=b,e[tot].pre=last[a],last[a]=tot,
e[++tot].too=a,e[tot].pre=last[b],last[b]=tot;
}
void dfs(int x,int fa){
zt[x]=;
int num[]={,,};
for(int i=last[x];i;i=e[i].pre)if(e[i].too!=fa)
dfs(e[i].too,x),num[zt[e[i].too]]++;
if(gg[x]&&deg[x]==)GG=;
if(gg[x])zt[x]=,ans+=num[];
else if(num[]&&num[])zt[x]=,ans++;
else if(num[]||num[])zt[x]=num[]?:;
else if(num[])zt[x]=;
// printf("x:%d zt:%d\n",x,zt[x]);
}
int main(){
n=read()+,m=read();
for(i=;i<n;i++)insert(read()+,read()+);
for(i=;i<=m;i++)gg[read()+]=;
for(i=n;i;i--)if(deg[i]==){dfs(i,),ans+=zt[i]==;break;}
printf("%d\n",!GG?ans:-);
}
上一篇:magento -- 解决magento错误:ERROR: Base table or view already exists: 1050 Table ... already exists


下一篇:HDU 5619 Jam's store