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的情形: ...
随机推荐
- 一句JS搞定只允许输入数字和字母
一句JS搞定输入框只允许用户输入数字和字母类型的内容,对象是input输入框,当然也可以其它对象,只不过input输入框用的频率非常高.一句代码,不信么?那就看下边代码: <INPUT clas ...
- 信息安全实验一:buffer-overflow
title: buffer-overflow date: 2016-01-10 14:17:17 categories: information-security tags: buffer-overf ...
- 安装centos mini版,无法联网,用yum安装软件提示 cannot find a valid baseurl for repo:base/7/x86_64 的解决方法
*无法联网的明显表现会有: cannot find a valid baseurl for repo:base/7/x86_64 1.yum install出现 Error: cannot find ...
- ural 1353. Milliard Vasya's Function
http://acm.timus.ru/problem.aspx?space=1&num=1353 #include <cstdio> #include <cstring&g ...
- C51程序优化
1.指针: 对于大部分的编译器,使用指针比使用数组生成的代码更短,执行效率更高.但是在Keil中则相反,使用数组比使用的指针生成的代码更短.通常使用自加.自减指令和复合赋值表达式(如a-=1及a+=1 ...
- COJ 0560 4015划分数
4015 划分数 难度级别:B: 运行时间限制:1000ms: 运行空间限制:262144KB: 代码长度限制:2000000B 试题描述 有n个无区别的物品,将他们划分成不超过m组,求出划分方法数模 ...
- Http请求工具实例编写
HTTP协议工作方式首先客户端发送一个请求(request)给服务器,服务器在接收到这个请求后将生成一个响应(response)返回给客户端.在这个通信的过程中HTTP协议在以下4个方面做了规定:1. ...
- C#中string类型是什么类型
- 鹿定制|Lu Couture|鹿定制·高级西装礼服私享定制品牌|芙蓉中路明城国际1425
鹿定制|Lu Couture|鹿定制·高级西装礼服私享定制品牌|芙蓉中路明城国际1425 联系我们
- 深入理解linux网络技术内幕读书笔记(九)--中断与网络驱动程序
Table of Contents 1 接收到帧时通知驱动程序 1.1 轮询 1.2 中断 2 中断处理程序 3 抢占功能 4 下半部函数 4.1 内核2.4版本以后的下半部函数: 引入软IRQ 5 ...