Hdu5385 The path
The path
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 995 Accepted Submission(s): 419
Special Judge
The length of one edge must ∈ [1,n]
It's guaranteed that there exists solution.
The first line contains two integers n and m,the number of vertexs and the number of edges.Next m lines contain two integers each, ui and vi (1≤ui,vi≤n), indicating there is a link between nodes ui and vi and the direction is from ui to vi.
∑n≤3∗105,∑m≤6∗105
1≤n,m≤105
4 6
1 2
2 4
1 3
1 2
2 2
2 3
4 6
1 2
2 3
1 4
2 1
2 1
2 1
2
2
1
4
4
1
1
3
4
4
4
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm> using namespace std; const int maxn = ; int T,n,m,head[maxn],nextt[maxn],to[maxn],tot = ,d[maxn],cnt;
bool vis[maxn]; struct node
{
int x,y,w;
}e[]; void add(int x,int y)
{
to[tot] = y;
nextt[tot] = head[x];
head[x] = tot++;
} int main()
{
scanf("%d",&T);
while (T--)
{
memset(head,,sizeof(head));
memset(vis,false,sizeof(vis));
memset(d,,sizeof(d));
cnt = ;
tot = ;
scanf("%d%d",&n,&m);
for (int i = ; i <= m; i++)
{
scanf("%d%d",&e[i].x,&e[i].y);
add(e[i].x,e[i].y);
}
d[] = ;
for (int i = head[];i;i = nextt[i])
{
int v = to[i];
vis[v] = ;
}
int l = ,r = n;
while (cnt < n)
{
int u;
if (vis[l])
u = l++;
else
u = r--;
d[u] = cnt++;
for (int i = head[u];i;i = nextt[i])
{
int v = to[i];
vis[v] = ;
}
}
for (int i = ; i <= m; i++)
{
if(e[i].x == e[i].y)
printf("%d\n",n);
else
printf("%d\n",abs(d[e[i].x] - d[e[i].y]));
}
} return ;
}
Hdu5385 The path的更多相关文章
- NodeJs之Path
Path模块 NodeJs提供的Path模块,使得我们可以对文件路径进行简单的操作. API var path = require('path'); var path_str = '\\Users\\ ...
- 【原】实时渲染中常用的几种Rendering Path
[原]实时渲染中常用的几种Rendering Path 本文转载请注明出处 —— polobymulberry-博客园 本文为我的图形学大作业的论文部分,介绍了一些Rendering Path,比较简 ...
- Node.js:path、url、querystring模块
Path模块 该模块提供了对文件或目录路径处理的方法,使用require('path')引用. 1.获取文件路径最后部分basename 使用basename(path[,ext])方法来获取路径的最 ...
- VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%
1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Thinking in Unity3D:渲染管线中的Rendering Path
关于<Thinking in Unity3D> 笔者在研究和使用Unity3D的过程中,获得了一些Unity3D方面的信息,同时也感叹Unity3D设计之精妙.不得不说,笔者最近几年的 ...
- node之path模块
node之path模块 原文链接 //引用该模块 var path = require("path"); 1.路径解析,得到规范化的路径格式 对window系统,目录分隔为'', ...
- Linux系统修改PATH环境变量方法
在Linux安装一些软件通常要添加路径环境变量PATH.PATH环境变量通俗的讲就是把程序的路径"备案"到系统中,这样执行这些程序时就不需要输入完整路径,直接在bash输入程序名就 ...
随机推荐
- 一个ssm综合小案例-商品订单管理-第一天
项目需求分析: 功能需求:登录,商品列表查询,修改 项目环境及技术栈: 项目构成及环境: 本项目采用 maven 构建 环境要求: IDEA Version: 2017.2.5 Tomcat Vers ...
- 优化MySQL的21个建议 – MySQL Life【转】
今天一个朋友向我咨询怎么去优化 MySQL,我按着思维整理了一下,大概粗的可以分为21个方向. 还有一些细节东西(table cache, 表设计,索引设计,程序端缓存之类的)先不列了,对一个系统,初 ...
- MySQL5.6快速安装【转】
下载MySQL5.6 访问MySQL官网 点击Downloads,然后选择Archives 选择MySQL Community Server 选择合适版本和平台 选择下载预先编译好的二进制安装包 将下 ...
- AUI-靠谱的移动前端框架
在如何开发出优秀的APICloud应用中ApiCloud官方推荐我们使用轻量级的框架AUI,针对AUI官网没有提供体验地址 特意编译了一个APP供给大家体验 aui官方地址:http://www.au ...
- Shiro:ajax的session超时处理
本问题解决方案参照网站多篇文章融合解决,在此表示感谢! 环境:springboot+shiro+jquery-easyui 问题:在ajax请求时,如果此时session已经失效,系统没有自动跳转到登 ...
- 错误/异常:java.net.SocketException: Unrecognized Windows Sockets error: 0: JVM_Bind;的解决方法
1.异常视图 2.解决方法 SocketException(JVM_Bind):套接口异常 说明:服务器端口号被占用 了 解决方法:点击 Window-->Preferences- ...
- Fiddler 常用功能总结
1.fiddler相关配置 2.如何抓包 移动端 ①保持手机和电脑处于同一网络中 ②设置手机的代理为电脑当前所处网络的IP,端口号为:8888,eg:10.12.1.64:8888. ③ 启动ap ...
- ASP.NET OAuth、jwt、OpenID Connect
ASP.NET OAuth.jwt.OpenID Connect 上一篇文章介绍了OAuth2.0以及如何使用.Net来实现基于OAuth的身份验证,本文是对上一篇文章的补充,主要是介绍OAuth与J ...
- 权限管理UI
vue+vuex+vue-router+EF的权限管理系统 演示网站 首先说下这个项目吧.如标题一样是基于VUE+.NET开发的框架,也是群友一直吼吼吼要一个vue版本的ABP框架.我们先来看看首页吧 ...
- 【LOJ】#2511. 「BJOI2018」双人猜数游戏
题解 设\(f[p][a][b]\)表示询问了\(p\)次,答案是\(a,b\)是否会被猜出来 然后判断如果\(p = 1\) 第一个问的\(Alice\),那么\([s,\sqrt{nm}]\)约数 ...