#include<bits/stdc++.h>
using namespace std;
const int maxn=1000+5;
int parent[maxn];
int find(int x)
{
return x==parent[x]?x:parent[x]=find(parent[x]);
}
int v,e;
void init()
{
for(int i=1;i<=v;i++)
parent[i]=i;
}
int main()
{
vector<int>G[maxn];
scanf("%d%d",&v,&e);
for(int i=1;i<=v;i++)
G[i].clear();
int query;
scanf("%d",&query);
int maxv=-1;
for(int i=0;i<e;i++)
{
int v1,v2;
scanf("%d%d",&v1,&v2);
G[v1].push_back(v2);
G[v2].push_back(v1);
}
while(query--)
{
init();
int k;
scanf("%d",&k);
for(int i=1;i<=v;i++)
{
if(i==k) continue;
for(int j=0;j<G[i].size();j++)
{
if(G[i][j]==k) continue;
int p1=find(i);
int p2=find(G[i][j]);
if(p1!=p2) parent[p1]=p2;
}
}
int num=0;
for(int i=1;i<=v;i++)
{
int p1=find(i);
if(p1==i) num++;
}
printf("%d\n",num-2);
}
return 0;
}
模拟
//模拟
#include<bits/stdc++.h>
using namespace std;
const int maxn=1000+5;
int main()
{
int n,m,k,q;
scanf("%d%d%d%d",&n,&m,&k,&q);
int time[maxn];
for(int i=1;i<=k;i++)
scanf("%d",&time[i]);
//预处理
int person[maxn];
memset(person,-1,sizeof(person));
queue<int>G[maxn];
for(int i=1;i<=n;i++)
{
while(!G[i].empty()) G[i].pop();
}
int wait=n*m+1,pos=0;
for(int i=1;i<=n*m;i++)
{
if(i>k) {
wait=-1;
break;
}
G[pos%n+1].push(i);
pos++;
}
int add[maxn];
memset(add,0,sizeof(add));
for(int i=1;i<=540;i++) //the time later
{
for(int j=1;j<=n;j++)
{
if(!G[j].empty())
{
pos=G[j].front();
person[pos]=add[j]; //记录开始时间
if(time[pos]+add[j]-i==0) {
add[j]+=time[pos];
G[j].pop();
if(wait!=-1&&i<540) {
G[j].push(wait++);
if(wait>k) wait=-1;
}
}
}
}
}
while(q--)
{
scanf("%d",&pos);
int x=person[pos];
if(x==-1) printf("Sorry\n");
else {
printf("%02d:%02d\n",8+(x+time[pos])/60,(x+time[pos])%60);
}
}
return 0;
}
#include<bits/stdc++.h>
using namespace std;
typedef pair<string,string>PII;
const int maxn=10+5;
int main()
{
int n,flag=0;
scanf("%d",&n);
PII str[1005];
for(int i=0;i<n;i++)
{
bool done=false;
char s1[maxn],s2[maxn];
scanf("%s%s",s1,s2);
for(int j=0;j<strlen(s2);j++)
{
if(s2[j]=='0'||s2[j]=='1'||s2[j]=='l'||s2[j]=='O') {
done=true;
if(s2[j]=='0') {
s2[j]='%';
}
if(s2[j]=='1') {
s2[j]='@';
}
if(s2[j]=='l') {
s2[j]='L';
}
if(s2[j]=='O') {
s2[j]='o';
}
}
}
if(done)
{
flag++;
str[flag].first=string(s1);
str[flag].second=string(s2);
}
}
if(flag==0) {
if(n==1) {
printf("There is 1 account and no account is modified\n");
}
else {
printf("There are %d accounts and no account is modified\n",n);
}
}
else {
cout<<flag<<endl;
for(int i=1;i<=flag;i++)
cout<<str[i].first<<" "<<str[i].second<<endl;
}
return 0;
}