HDOJ 5385 The path 构造
来源:互联网 发布:网络加速器国外节点 编辑:程序博客网 时间:2024/06/10 19:40
The path
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 521 Accepted Submission(s): 190
Special Judge
Problem Description
You have a connected directed graph.Let d(x) be the length of the shortest path from 1 to x .Specially d(1)=0 .A graph is good if there exist x satisfy d(1)<d(2)<....d(x)>d(x+1)>...d(n) .Now you need to set the length of every edge satisfy that the graph is good.Specially,if d(1)<d(2)<..d(n) ,the graph is good too.
The length of one edge must∈ [1,n]
It's guaranteed that there exists solution.
The length of one edge must
It's guaranteed that there exists solution.
Input
There are multiple test cases. The first line of input contains an integer T , indicating the number of test cases. For each test case:
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
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,
Output
For each test case,print m lines.The i-th line includes one integer:the length of edge from ui to vi
Sample Input
24 61 22 41 31 22 22 34 61 22 31 42 12 12 1
Sample Output
122144113444
Author
SXYZ
Source
2015 Multi-University Training Contest 8
/* ***********************************************Author :CKbossCreated Time :2015年08月15日 星期六 12时15分02秒File Name :HDOJ5385_2.cpp************************************************ */#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <string>#include <cmath>#include <cstdlib>#include <vector>#include <queue>#include <set>#include <map>using namespace std;const int maxn=100100;struct P{int from,to,len;}ep[maxn];struct Edge{int to,next,id;}edge[maxn];int Adj[maxn],Size;int n,m;int Time[maxn];bool vis[maxn];void init(){memset(Time,0,sizeof(Time));memset(vis,false,sizeof(vis));memset(Adj,-1,sizeof(Adj)); Size=0;}void Add_Edge(int u,int v,int id){edge[Size].to=v;edge[Size].id=id;edge[Size].next=Adj[u];Adj[u]=Size++;}bool ans[maxn];void color(int u,int t){Time[u]=t;for(int i=Adj[u];~i;i=edge[i].next){int v=edge[i].to;int eid=edge[i].id;if(vis[v]==true) continue;ans[eid]=true;vis[v]=true;}}int main(){//freopen("in.txt","r",stdin);//freopen("out.txt","w",stdout);int T_T;scanf("%d",&T_T);while(T_T--){init();scanf("%d%d",&n,&m);for(int i=0,u,v;i<m;i++){scanf("%d%d",&u,&v);Add_Edge(u,v,i);ep[i].from=u; ep[i].to=v; ep[i].len=-1;}int ti=1;int s=1,e=n;vis[1]=true; Time[1]=1;memset(ans,false,sizeof(ans));while(s<=e){if(vis[s]) color(s++,ti++);if(vis[e]) color(e--,ti++);}for(int i=0;i<m;i++){if(ans[i]) printf("%d\n",abs(Time[ep[i].from]-Time[ep[i].to]));else printf("%d\n",n);}} return 0;}
0 0
- HDOJ 5385 The path 构造
- hdu 5385 The path 构造
- hdu 5385 The path 贪心?构造
- HDU 5385 The path(构造)
- HDU 5385 The path(贪心+构造)
- hdoj-5883-The Best Path
- hdoj 5883 The Best Path
- hdu 5385 The path(最短路+构造)
- HDU 5385(The path-构造最短路树)
- HDOJ 5883 The Best Path 欧拉路
- HDU5385 The path (构造最短路 BFS)
- HDOJ 5302 Connect the Graph 构造
- HDU 5385 The path
- hdu 5385 The path
- [HDOJ 4916] Count on the path [树+乱搞]
- hdoj 2224 && poj 2677 The shortest path 【TSP】
- hdoj 4725 The Shortest Path in Nya Graph
- hdu 5385 The path 贪心
- 360云 Ubuntu安装Dokcer
- 素数
- linux压缩解压缩
- vim/vi配置及用法
- JPA学习笔记(8)——映射一对多关联关系
- HDOJ 5385 The path 构造
- 创建堆,堆排序的详细实现过程,C++完整代码
- 我们常常忽略了自己在谈判
- 用Discuz 搭建个人论坛
- 添加超链接
- Watch OS 2 Complication 开发教程 (二) (持续连载中)
- 机器学习理论依据
- linux常用命令
- HashMap和HashSet的底层实现