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的情形: ...
随机推荐
- Symfony2 EventDispatcher组件
一个插件系统中,A插件在不影响其它插件的前提下,添加新的方法,或者在一个方法运行前做一些准备工作,通过继承来实现扩展是很不容易的,由于插件之间的关联关系,A插件的改变也会使得关联的插件 ...
- Spark运行问题备忘一(网络搜集)
问题一 ERROR storage.DiskBlockObjectWriter: Uncaught exception -9ca8//shuffle_1_1562_27 java.io.FileNot ...
- Android 每隔3s更新一次title
MainActivity.java public class MainActivity extends Activity { private static int i=0; @Override pro ...
- Cracking the coding interview--Q1.6
原文: Given an image represented by an NxN matrix, where each pixel in the image is 4 bytes, write a m ...
- 深入理解JavaScript Hijacking原理
最近在整理关于JavaScript代码安全方面的资料,在查关于JavaScript Hijacking的资料时,发现关于它的中文资料很少,故特意整理一下. 一.JavaScript Hijacking ...
- Python socket 客户端和服务器端
connection, address = socket.accept() 调 用accept方法时,socket会时入“waiting”状态.客户请求连接时,方法建立连接并返回服务器.accept方 ...
- 设计模式 ( 十六 ): Mediator中介者模式 -- 行为型
1.概述 在面向对象的软件设计与开发过程中,根据“单一职责原则”,我们应该尽量将对象细化,使其只负责或呈现单一的职责,即将行为分布到各个对象中. 对于一个模块或者系统,可能由很多对象构成,而且这些对象 ...
- iOS 9之Safari广告拦截器(Content Blocker)
金田( github 示例源码) 相对于谷歌对广告拦截的禁止,苹果与之态度截然相反,继Mac版Safari加入广告拦截工具之后,即将到来的iOS9对Safari也引入了内容拦截插件-Content B ...
- Java---设计模块(单例的变形)(多例)
设计模式1--单例变形(多例) ★ 缓存在单例中的使用 缓存在编程中使用很频繁,有着非常重要的作用,它能够帮助程序实现以空间换取时间,通常被设计成整个应用程序所共享的一个空间,现要求实现一个用缓存存放 ...
- 寻找第K小元素
要在一个序列里找出第K小元素,可以用排序算法,然后再找.可以证明,排序算法的上界为O(nlogn). 在这里,给出两种可以在线性时间内找出第K小元素的方法. 方法1: (1) 选定一个比较小的阈值(如 ...