【Loj #10100. 「一本通 3.6 练习 1」网络】题解
作者:互联网
题目链接
题目就是给出一幅图,求其割点个数。
由于 \(n\leqslant 100\),所以可以暴力删点。
当然也可以跑割点。
(感谢crx老师教我割点模板)
暴力Code
// Problem: #10100. 「一本通 3.6 练习 1」网络
// Contest: LibreOJ
// URL: https://loj.ac/p/10100
// Memory Limit: 10 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
//#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define mo
#define N 110
struct node
{
int x, y, n;
}d[N*N*2];
int n, m, i, j, k;
int x, y, z, ans;
int h[N], c[N];
char ch;
void cun(int x, int y)
{
d[++k].x=x; d[k].y=y;
d[k].n=h[x]; h[x]=k;
}
void init()
{
m=i=j=k=x=y=z=ans=ch=0;
memset(h, 0, sizeof(h));
memset(c, 0, sizeof(c));
memset(d, 0, sizeof(d));
}
void dfs(int x)
{
for(int g=h[x]; g; g=d[g].n)
{
int y=d[g].y;
if(c[y]) continue;
c[y]=1;
dfs(y);
}
}
signed main()
{
// freopen("tiaoshi.in","r",stdin);
// freopen("tiaoshi.out","w",stdout);
n=read();
while(n)
{
init();
scanf("%d", &i);
while(i)
{
scanf("%d%c", &j, &ch);
// printf("%d %d\n", i, j);
cun(i, j); cun(j, i);
while(ch>=32)
{
scanf("%d%c", &j, &ch);
// printf("%d %d\n", i, j);
cun(i, j); cun(j, i);
}
scanf("%d", &i);
// printf("%d\n", i);
}
i=k=0;
for(j=1; j<=n; ++j)
if(!c[j]) c[j]=1, dfs(j), ++k;
// printf("k:%d\n", k);
for(i=1; i<=n; ++i)
{
memset(c, 0, sizeof(c));
c[i]=1; m=0;
for(j=1; j<=n; ++j)
if(!c[j]) c[j]=1, dfs(j), ++m;
if(m!=k) ++ans;
// printf("m:%d\n", m);
}
printf("%d\n", ans);
n=read();
}
return 0;
}
割点Code
// Problem: #10100. 「一本通 3.6 练习 1」网络
// Contest: LibreOJ
// URL: https://loj.ac/p/10100
// Memory Limit: 10 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)
#include<bits/stdc++.h>
using namespace std;
//#define int long long
inline int read(){int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;
ch=getchar();}while(ch>='0'&&ch<='9'){x=(x<<1)+
(x<<3)+(ch^48);ch=getchar();}return x*f;}
//#define mo
#define N 110
struct node
{
int x, y, n;
}d[N*N*2];
int n, m, i, j, k;
int x, y, z, ans;
int h[N], c[N], f[N], zi[N];
char ch;
void cun(int x, int y)
{
d[++k].x=x; d[k].y=y;
d[k].n=h[x]; h[x]=k;
}
void init()
{
m=i=j=k=x=y=z=ans=ch=0;
memset(h, 0, sizeof(h));
memset(c, 0, sizeof(c));
memset(d, 0, sizeof(d));
memset(f, 0, sizeof(f));
memset(zi, 0, sizeof(zi));
}
void dfs(int x)
{
for(int g=h[x]; g; g=d[g].n)
{
int y=d[g].y;
if(!c[y])
{
c[y]=c[x]+1;
dfs(y);
if(c[f[y]]<c[f[x]]) f[x]=f[y];
if(c[f[y]]>=c[x]) ++zi[x];
}
else if(c[y]<c[f[x]]) f[x]=y;
}
}
signed main()
{
// freopen("tiaoshi.in","r",stdin);
// freopen("tiaoshi.out","w",stdout);
n=read();
while(n)
{
init();
scanf("%d", &i);
while(i)
{
scanf("%d%c", &j, &ch);
// printf("%d %d\n", i, j);
cun(i, j); cun(j, i);
while(ch>=32)
{
scanf("%d%c", &j, &ch);
// printf("%d %d\n", i, j);
cun(i, j); cun(j, i);
}
scanf("%d", &i);
// printf("%d\n", i);
}
for(i=1; i<=n; ++i) f[i]=i;
for(i=1; i<=n; ++i)
if(!c[i]) c[i]=1, dfs(i);
for(i=1; i<=n; ++i)
if((zi[i]>1)||(f[i]!=i&&zi[i])) ++ans;
printf("%d\n", ans);
n=read();
}
return 0;
}
标签:ch,Loj,题解,scanf,3.6,int,printf,10100,getchar 来源: https://www.cnblogs.com/zhangtingxi/p/15620690.html