裸题一个
/*
ID: CUGB-wwj
PROG:
LANG: C++
*/
#include <iostream>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cmath>
#include <ctime>
#define INF 1111111111
#define MAXN 1005
#define MAXM 1000005
#define L(x) x<<1
#define R(x) x<<1|1
#define eps 1e-4
using namespace std;
vector<int>tree[MAXN], ask[MAXN];
int father[MAXN], vis[MAXN], ans[MAXN], in[MAXN];
int n, m, c;
void init()
{
for(int i = 0; i <= n; i++)
{
father[i] = i;
vis[i] = 0;
tree[i].clear();
ask[i].clear();
ans[i] = 0;
in[i] = 0;
}
}
int find(int x)
{
if(father[x] == x) return x;
int t = find(father[x]);
father[x] = t;
return t;
}
void LCA(int u)
{
father[u] = u;
int size = tree[u].size();
for(int i = 0; i < size; i++)
{
LCA(tree[u][i]);
father[tree[u][i]] = u;
}
vis[u] = 1;
size = ask[u].size();
for(int i = 0; i < size; i++)
if(vis[ask[u][i]] == 1)
ans[find(ask[u][i])]++;
}
int main()
{
int x, y, t;
while(scanf("%d", &n) != EOF)
{
init();
for(int i = 1; i <= n; i++)
{
scanf("%d:(%d)", &x, &t);
while(t--)
{
scanf("%d", &y);
tree[x].push_back(y);
in[y]++;
}
}
scanf("%d", &m);
for(int i = 1; i <= m; i++)
{
scanf(" (%d %d)", &x, &y);
ask[x].push_back(y);
ask[y].push_back(x);
}
for(int i = 1; i <= n; i++)
if(in[i] == 0) LCA(i);
for(int i = 1; i <= n; i++)
if(ans[i]) printf("%d:%d\n", i, ans[i]);
}
return 0;
}
分享到:
相关推荐
2. bool nodePath (bstNode* pRoot, int value, std::vector*>& path) 3. { 6
POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类POJ分类
poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题报告poj 解题...
poj 2763 程序 线段树 LCA 2000MS AC
POJ第1861题源码 POJ第1861题源码 POJ第1861题源码
poj分类poj分类poj分类poj分类
北大POJ1159-Palindrome 解题报告+AC代码
poj 3414解题报告poj 3414解题报告poj 3414解题报告poj 3414解题报告
C语言 poj npu 西工大 C语言Poj答案全完整打包,给有需要的朋友
poj 1012解题报告poj 1012解题报告poj 1012解题报告poj 1012解题报告
poj 2329解题报告poj 2329解题报告poj 2329解题报告poj 2329解题报告
poj 1659解题报告poj 1659解题报告poj 1659解题报告poj 1659解题报告
POJ1503解答 POJ1503解答,正确答案(已通过POJ)
北大POJ2002-Squares 解题报告+AC代码
POJ1048,加强版的约瑟夫问题 难度中等
POJ1083的代码,POJ1083的代码,POJ1083的代码
poj 百练 题目分类 poj 百练 题目分类
poj 1001答案
POJ2968代码有用,欢迎下载,POJ代码
poj 1440解题报告 poj 1440解题报告 poj 1440解题报告 poj 1440解题报告