2014
02-12

# Installing Software

Installing software in Windows is a piece of cake: just download and install the software, then you can use it. Although installing a software in Linux only needs typing yum install thename in the command lines in some Linux distribution,especially Fedora/Red Hat,it requires a lot extra time in a process called resolving dependency(means the period of downloading the other packages it depends on in order to install itself completely and successfully).
The problem is designed like this:
Suppose Samuel needs to install software A,A depends on B,C,D,E,and Samuel has already installed package E in his system so in the command lines there only will appear the packages B,C,D,we can say it needs 3 packages to finish the installation.

The number of test cases t,each of the case has an integer m means m packages to depend on if want to install X successfully and completely. Then the next line will contain m(m<=26 the letters are A-Z only) letters represent the name of each packages. The an integer n(n<=26 the letters are A-Z only too),means n packages have been installed in the desktop of Samuel.

The number of test cases t,each of the case has an integer m means m packages to depend on if want to install X successfully and completely. Then the next line will contain m(m<=26 the letters are A-Z only) letters represent the name of each packages. The an integer n(n<=26 the letters are A-Z only too),means n packages have been installed in the desktop of Samuel.

3
3
A B C
2
A B
5
A B E D F
3
A B F
2
A B
2
A B

Samuel has to install another 1 package(s) in addition,the packages is/are C.
Samuel has to install another 2 package(s) in addition,the packages is/are E,D.
Samuel can install the software without installing anything else.

#include <stdio.h>

#include <iostream>

#include <string>

#include <iomanip>

#include <sstream>

#include <cstring>

#include <algorithm>

#include <cmath>

#include <queue>

#include <vector>

#include <map>

#include <memory.h>

using namespace std;

#define maxn 5555

int p[maxn];

int n,m,q;

int findset(int x){

return p[x]==x? x:p[x]=findset(p[x]);

}

int main() {

int a,b,x,y;

while(scanf("%d%d%d",&n,&m,&q)==3){

for(int i=1;i<=n;i++) p[i]=i;

for(int i=1;i<=m;i++){

scanf("%d%d",&a,&b);

x=findset(a);

y=findset(b);

if(x!=y)  p[x]=y;

}

for(int i=1;i<=q;i++){

scanf("%d%d",&a,&b);

x=findset(a);

y=findset(b);

if(x!=y) printf("no\n");

else printf("yes\n");

}

}

return 0;

}

1. #include <stdio.h>
int main(void)
{
int arr[] = {10,20,30,40,50,60};
int *p=arr;
printf("%d,%d,",*p++,*++p);
printf("%d,%d,%d",*p,*p++,*++p);
return 0;
}

为什么是 20,20,50,40,50. 我觉得的应该是 20,20,40,40,50 . 谁能解释下？

2. 在方法1里面：

//遍历所有的边，计算入度
for(int i=0; i<V; i++)
{
degree = 0;