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的情形: ...
随机推荐
- Python自动化运维之11、面向对象基础
一.简介 面向对象编程是一种编程方式,使用 “类” 和 “对象” 来实现,所以,面向对象编程其实就是对 “类” 和 “对象” 的使用.类就是一个模板,模板里可以包含多个方法(函数),方法里实现各种各样 ...
- twisted(3)--再谈twisted
上一章,我们直接写了一个小例子来从整体讲述twisted运行的大致过程,今天我们首先深入一些概念,在逐渐明白这些概念以后,我们会修改昨天写的例子. 先看下面一张图: 这个系列的第一篇文章,我们已经为大 ...
- jquery编写插件
jquery编写插件的方法 版权声明:作者原创,转载请注明出处! 编写插件的两种方式: 1.类级别开发插件(1%) 2.对象级别开发(99%) 类级别的静态开发就是给jquery添加静态方法,三 ...
- Update主循环、状态机的实现
从写一段程序,到写一个app,写一个游戏,到底其中有什么不同呢?一段程序的执行时间很短,一个应用的执行时间很长,仅此而已. 游戏中存在一个帧的概念. 这个概念大家都知道,类比的话,它就是电影胶卷的 ...
- QuerryRunner Tools
package com.ydbg.gis.utils; import java.sql.SQLException; import java.util.List; import java.util.Ma ...
- Ubuntu 下升级git到最新版
$ sudo add-apt-repository ppa:git-core/ppa $ sudo apt-get update $ sudo apt-get install git
- html标签引入外部html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- windows环境变量如何在cmd中打印
在windows的cmd下,用"set"命令可以得到全部的环境变量,如何想得到某个环境变量,直接这样"set path"就可以了. set不仅如何,还有其他功能 ...
- curl_easy_setopt-curl库的关键函数之一
函数原型:#include <curl/curl.h>CURLcodecurl_easy_setopt(CURL *handle, CURLoption option, parameter ...
- SPOJ694 -- DISUBSTR 后缀树组求不相同的子串的个数
DISUBSTR - Distinct Substrings Given a string, we need to find the total number of its distinct su ...