uva 280 - Vertex
#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的更多相关文章
- [ZZ] GTX 280 GPU architecture
http://anandtech.com/show/2549 Now that NVIDIA’s has announced its newest GPU architecture (the GeFo ...
- UVA 1424 二 Salesmen
Salesmen Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Status Pr ...
- UVa 10012 - How Big Is It? 堆球问题 全排列+坐标模拟 数据
题意:给出几个圆的半径,贴着底下排放在一个长方形里面,求出如何摆放能使长方形底下长度最短. 由于球的个数不会超过8, 所以用全排列一个一个计算底下的长度,然后记录最短就行了. 全排列用next_per ...
- UVA - 11090 - Going in Cycle!!(二分+差分约束系统)
Problem UVA - 11090 - Going in Cycle!! Time Limit: 3000 mSec Problem Description You are given a we ...
- UVA - 11478 - Halum(二分+差分约束系统)
Problem UVA - 11478 - Halum Time Limit: 3000 mSec Problem Description You are given a directed grap ...
- UVA LIVE-3263 - That Nice Euler Circuit
画一个顶点为偶数的封闭的二维图,当然.这个图能够自交,给出画的过程中的一些轨迹点.求出这个图把二次元分成了几部分,比如三角形把二次元分成了两部分. 这个的话,有图中顶点数+部分数-棱数=2的定律,这是 ...
- UVA 11478 Halum
Halum Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 114 ...
- Fast Matrix Operations(UVA)11992
UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...
- CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总
CSharpGL(38)带初始数据创建Vertex Buffer Object的情形汇总 开始 总的来说,OpenGL应用开发者会遇到为如下三种数据创建Vertex Buffer Object的情形: ...
随机推荐
- Autofact 的使用
资料: http://www.cnblogs.com/linhan/p/4298971.html --其他博友 http://autofac.org/# --官网 http://efmvc.codep ...
- java反射 -Class类
Class类:任何类都是Class类的对象 Class类的实例对象的三种表现形式:1.通过某个类的.class实现 2.某个类的对象的getClass()方法 3.Class.forName() 注意 ...
- PHP 中的数组
PHP中的数组是指一个键/值对的集合.PHP中的数组是使用哈系表构建的,这意味着访问每一个值都会有一个平均的O(1)复杂度. $arr=array([key=>]value,....); 在这里 ...
- IO 常用
1. read file from folder DirectoryInfo folder = new DirectoryInfo(@"C:\Users\keatkeat\Desktop\K ...
- java8-concurrency-tutorial-thread-executor-examples
http://ifeve.com/java8-concurrency-tutorial-thread-executor-examples/
- Android项目的图标
项目的图标就是在AndroidManifest.xml中通过android:icon="@drawable/ic_launcher"来指定的,ic_launcher这张图片可以放在 ...
- drawBitmapMesh方法关键参数的说明
bitmap:指定需要扭曲的源位图.meshWidth:该参数控制在横向上把该源位图划分成多少格.meshHeight:该参数控制在纵向上把该源位图划分成多少格.verts:该参数是一个长度为(mes ...
- 关于Action返回结果类型的事儿(下)
原文:关于Action返回结果类型的事儿(下) using System; using System.Collections.Generic; using System.Linq; using ...
- bzoj3791 作业
Description 众所周知,白神是具有神奇的能力的. 比如说,他对数学作业说一声“数”,数学作业就会出于畏惧而自己完成:对语文作业说一声“语”,语文作业就会出于畏惧而自己完成. 今天,语文老师和 ...
- Missing Ranges 解答
Question Given a sorted integer array where the range of elements are in the inclusive range [lower, ...