#include <iostream>
#include <cstdio>
using namespace std; #include <vector>
#define loop(i, n) for (int i = 0; i < n; i++)
#define loopfrom1(i, n) for (int i =1; i < n; i++)
#define pb(a) push_back(a)
#define SZ size()
#define getint(n) scanf("%d", &n) #define MAXX 105
#define looptill(i, n) for (int i = 0; i <= n; i++) vector<int> Graph[MAXX];
bool visited[MAXX];
int inaccessible; void dfs(int u)
{
int len = Graph[u].SZ;
int v;
loop(i, len)
{
v = Graph[u][i];
if( ! visited[v] )
{
visited[v] = true;
inaccessible --;
dfs(v);
}
}
} int main()
{
int number_of_nodes, total_nodes;
int node1, node2;
while(true)
{
getint(total_nodes);
if(total_nodes == ) break;
looptill(i, total_nodes)
{
Graph[i].clear();
} while(true)
{
getint(node1);
if(node1 == ) break;
while(true)
{
getint (node2);
if(node2 == ) break;
Graph[node1].pb(node2);
}
} getint(number_of_nodes);
loop(t, number_of_nodes)
{
looptill(i, total_nodes)
{
visited[i] = false;
} getint(node1);
inaccessible = total_nodes;
dfs(node1); cout << inaccessible; for (int j = ; j <= total_nodes; j++)
{
if( ! visited[j] )
{
cout <<" "<<j;
}
}
cout << endl;
}
}
return ;
}
 // @BEGIN_OF_SOURCE_CODE

 #include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#define For(a) for ( i = 0; i < a; i++ )
#define Rep(a, b) for ( i = a; i <= b; i++ )
#define N 1000000
using namespace std; enum related_color {gray, white, black}; bool matrix [ + ] [ + ];
bool related_vertics [ + ];
related_color color [ + ];
int number_of_vertics_n; void reset_all (int n)
{
for ( int i = ; i < n; i++ ) {
for ( int j = ; j < n; j++ )
matrix [i] [j] = false;
}
} void dfs (int u)
{
color [u] = gray; for ( int i = ; i < number_of_vertics_n; i++ ) {
if ( matrix [u] [i] ) {
related_vertics [i] = true;
if ( color [i] == white ) {
related_vertics [i] = true;
dfs (i);
}
}
} color [u] = black;
} int main ()
{
while ( scanf ("%d", &number_of_vertics_n) && number_of_vertics_n ) {
reset_all (number_of_vertics_n); int starting_vertex; while ( scanf ("%d", &starting_vertex) && starting_vertex ) {
int series_of_edges;
while ( scanf ("%d", &series_of_edges) && series_of_edges ) {
matrix [starting_vertex - ] [series_of_edges - ] = true;
}
} int testCase;
scanf ("%d", &testCase); while ( testCase-- ) {
int query;
scanf ("%d", &query); for ( int i = ; i < number_of_vertics_n; i++ ) {
related_vertics [i] = false;
color [i] = white;
} dfs (query - ); vector <int> v; for ( int i = ; i < number_of_vertics_n; i++ ) {
if ( !related_vertics [i] )
v.push_back (i + );
} printf ("%d", v.size ()); for ( unsigned int i = ; i < v.size (); i++ )
printf (" %d", v [i]); printf ("\n");
} /*
for ( int i = 0; i < number_of_vertics_n; i++ ) {
for ( int j = 0; j < number_of_vertics_n; j++ )
related_vertics [j] = false; dfs (i); for ( int j = 0; j < number_of_vertics_n; j++ ) {
if ( related_vertics [j] )
matrix [i] [j] = true;
}
}
*/
} return ;
} // @END_OF_SOURCE_CODE

uva 280 - Vertex的更多相关文章

  1. [ZZ] GTX 280 GPU architecture

    http://anandtech.com/show/2549 Now that NVIDIA’s has announced its newest GPU architecture (the GeFo ...

  2. UVA 1424 二 Salesmen

    Salesmen Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Pr ...

  3. UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据

    题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...

  4. UVA - 11090 - Going in Cycle!!(二分+差分约束系统)

    Problem  UVA - 11090 - Going in Cycle!! Time Limit: 3000 mSec Problem Description You are given a we ...

  5. UVA - 11478 - Halum(二分+差分约束系统)

    Problem  UVA - 11478 - Halum Time Limit: 3000 mSec Problem Description You are given a directed grap ...

  6. UVA LIVE-3263 - That Nice Euler Circuit

    画一个顶点为偶数的封闭的二维图,当然.这个图能够自交,给出画的过程中的一些轨迹点.求出这个图把二次元分成了几部分,比如三角形把二次元分成了两部分. 这个的话,有图中顶点数+部分数-棱数=2的定律,这是 ...

  7. UVA 11478 Halum

    Halum Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 114 ...

  8. Fast Matrix Operations(UVA)11992

    UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...

  9. CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总

    CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总 开始 总的来说,OpenGL应用开发者会遇到为如下三种数据创建Vertex Buffer Object的情形: ...

随机推荐

  1. 不能将值 NULL 插入列 'ID',表 'EupStoreDemoDB.dbo.OrderDiary';列不允许有 Null 值。INSERT 失败。

    MVC,使用EF构建实体.将数据存入数据库,执行到_db.SaveChange()时,会报如下错误:

  2. d023: 各位数字之和

    内容: 求输入的一个整数的各位数字之和 输入说明: 一行一个整数 输出说明: 一个整数 输入样例: 2147483646 输出样例 : 45 #include <stdio.h> int ...

  3. Unity3D 经验记录

    1.using UnityEngine.SceneManagement; 当在01场景调用02场景时,再载入回01场景时,代码保存的变量不会初始化,预制物体脚本内的变量会初始化. 2.当子物体太多时, ...

  4. SVM详解

    SVM入门(一)至(三)Refresh 按:之前的文章重新汇编一下,修改了一些错误和不当的说法,一起复习,然后继续SVM之旅. (一)SVM的简介 支持向量机(Support Vector Machi ...

  5. TimeZone 时区 (JS .NET JSON MYSQL)

    来源参考 : http://www.cnblogs.com/qiuyi21/archive/2008/03/04/1089456.html 来源参考 : http://walkingice.blogs ...

  6. keil #pragma disable

    μVision2 控制:这条命令不能在命令行使用,只能在源文件中使用. 功能:DISABLE 指令使得编译器在函数运行期间禁止所有中断产生.DISABLE命令必须在函数的前面以#pragma 参数的形 ...

  7. 【网贷投资手册】P2P行业揭秘

    [网贷投资手册]P2P行业揭秘     (中国电子商务研究中心讯)如果你手头有100元,你会拿它来做什么?跟好朋友去吃一顿?跟女朋友去看场电影?还是……你会想到拿100元去投资吗?100元太少了,买一 ...

  8. The Black Tux | IT桔子

    The Black Tux | IT桔子 The Black Tux theblacktux.com

  9. Git分支学习总结

    思维导图:        总结:        Git分支:分为2类合计为5种分支.        第一类:主分支和开发分支.        第二类:特性分支,热补丁分支,版本分支.

  10. eclipse tomcat 网页404的一个小问题

    之前一篇文章说过关于修改tomcat布置的应用的localhost路径.因为有两个项目在eclipse,所以我每次启动tomcat的时候都会加载两个项目, 但我其实只用调试其中一个项目,所以我就在se ...