2013
12-13

# 九度-1526-朋友圈[解题代码]

5 3
1 2
2 3
4 5
3 3
1 2
1 3
2 3
0

2
1


cpp 代码如下：
#include <stdio.h>
int n, m, f[100001],i;

int findSet(int x) {
int t = x;
while (f[x] > 0)
x = f[x];
while (t != x) { //路径压缩
int q = f[t];
f[t] = x;
t = q;
}
return x;
}

void unionSet(int x, int y) {
int fx = findSet(x);
int fy = findSet(y);
if (fx != fy) {
n--;
f[fx] = fy;
//		int tmp = f[fx] + f[fy];//两个集合个数之和
//		if (f[fx] < f[fy]) {  //大集合 吞并小集合.
//			f[fy] = fx;
//			f[fx] = tmp;
//		} else {
//			f[fx] = fy;
//			f[fy] = tmp;
//		}
}
}

int main() {
int a,b;
while(scanf("%d",&n), n) {
scanf("%d", &m);
for( i=1; i<=n; i++)
f[i] = -1;
for(i=0; i<m; i++) {
scanf("%d %d", &a,&b);
unionSet(a,b);
}
printf("%d\n", n);
}
return 0;
}
/**************************************************************
Problem: 1526
User: coder
Language: C
Result: Accepted
Time:220 ms
Memory:1304 kb
****************************************************************/

1. 网站做得很好看，内容也多，全。前段时间在博客园里看到有人说：网页的好坏看字体。觉得微软雅黑的字体很好看，然后现在这个网站也用的这个字体！nice!

2. /*
* =====================================================================================
*
* Filename: 1366.cc
*
* Description:
*
* Version: 1.0
* Created: 2014年01月06日 14时52分14秒
* Revision: none
* Compiler: gcc
*
* Author: Wenxian Ni (Hello World~), [email protected]
* Organization: AMS/ICT
*
* =====================================================================================
*/

#include
#include

using namespace std;

int main()
{
stack st;
int n,i,j;
int test;
int a[100001];
int b[100001];
while(cin>>n)
{
for(i=1;i>a[i];
for(i=1;i>b[i];
//st.clear();
while(!st.empty())
st.pop();
i = 1;
j = 1;

while(in)
break;
}
while(!st.empty()&&st.top()==b[j])
{
st.pop();
j++;
}
}
if(st.empty())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}