URAL 2013 Neither shaken nor stirred dfs 模拟
来源:互联网 发布:c语言获取系统时间 编辑:程序博客网 时间:2024/05/16 18:17
题目链接:点击打开链接
题意:
给定n个点的有向图:
下面n行,第一个数字表示点权,后面一个数字m表示有m条边。
起点是1.
对于每个点,输出2个值表示前驱点权1和该点点权2。
1、若有多条路径到达该点且前驱的点权存在>0则输出unknown,否则输出前驱的点权(就是若有多条路径且全为0输出0,否则若只有一条路径则输出前驱点权,否则输出unknown)
2、若1输出的是0,则输出该点点权,否则若该点点权>0输出该点点权,否则输出前驱点权。
==略繁琐
#include <cstdio>#include <cstring>#include <cstring>#include <vector>using namespace std;template <class T>inline bool rd(T &ret) {char c; int sgn;if (c = getchar(), c == EOF) return 0;while (c != '-' && (c<'0' || c>'9')) c = getchar();sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');while (c = getchar(), c >= '0'&&c <= '9') ret = ret * 10 + (c - '0');ret *= sgn;return 1;}template <class T>inline void pt(T x) {if (x <0) {putchar('-');x = -x;}if (x>9) pt(x / 10);putchar(x % 10 + '0');}const int N = 100005;vector<int> g[N];int k[N], f[N][2], vis[N];void dfs(int idx, int fa) {if(vis[idx]) {if(f[idx][0] != f[fa][1]) {f[idx][0] = -1;if(!k[idx]) {f[idx][1] = -1;for(int i = 0; i < (int)g[idx].size(); i ++) {int u = g[idx][i];dfs(u, idx);}}}return ;}vis[idx] = 1;f[idx][0] = f[fa][1];f[idx][1] = k[idx] ? k[idx] : f[idx][0];for(int i = 0; i < (int)g[idx].size(); i ++) {int u = g[idx][i];dfs(u, idx);}}int main() {int n, m;while (~scanf("%d", &n)) {memset(vis, 0, sizeof vis);//memset(f, 0, sizeof f);for(int i = 1; i <= n; i ++) g[i].clear();for(int i = 1; i <= n; i ++) {rd(k[i]), rd(m);for(int j = 0, x; j < m; j ++) {rd(x);g[i].push_back(x);}}vis[1] = 1;f[1][0] = 0;f[1][1] = k[1];for(int i = 0; i < (int)g[1].size(); i ++) {int u = g[1][i];dfs(u, 1);}for(int i = 1; i <= n; i ++) {if(f[i][0] == -1) printf("unknown ");else if(f[i][0] == 0) printf("sober ");else {pt(f[i][0]);putchar(' ');}if(f[i][1] == -1) printf("unknown\n");else if(f[i][1] == 0) printf("sober\n");else {pt(f[i][1]);putchar('\n');}}}return 0;}
0 0
- URAL 2013 Neither shaken nor stirred dfs 模拟
- 初中--浅谈 either...or...与 neither...nor...
- linux安装tomcat Neither the JAVA_HOME nor the JRE_HOME environment variable is defined 原创 2013年07月26日
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- This element neither has attached source nor attached Javadoc
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Spring3 MVC: Neither BindingResult nor plain target object fo...
- SecurityException: Neither nor current process has android.permission.INSTALL_PACKAGES
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither the JAVA_HOME nor the JRE_HOME environment variable is defined
- Neither user 10029 nor current process has android.permission.WRITE_MEDIA_STORAGE.
- This element neither has attached source nor attached Javadoc
- Table is neither enables nor disabled in HBase
- Neither BindingResult nor plain target object for bean
- Neither GenericXmlContextLoader nor AnnotationConfigContextLoader was able to detect defaults
- linux top详解
- vpn
- windows下使用VS2010编译jpeglib(实际操作vs2008也可以)
- C#网络编程,多个客户端连接服务器端并发送消息
- 指针函数与函数指针的区别
- URAL 2013 Neither shaken nor stirred dfs 模拟
- Ubuntu + Nginx + php + swpan-fcgi 搭建php网络服务
- Python的网页爬虫&文本处理&科学计&机器学习&数据挖掘工具集
- kernel panic 调试方法(3)-Backtrace
- 子线程返回前,使循环暂停但不使主线程卡死的办法,等待子线程有返回了之后,才执行主线程下一步代码的方法
- SQL中DATENAME函数的用法
- DWR实例教程开发步骤及注意事项
- substring的用法
- html自动适应手机屏幕