HDU 5385
来源:互联网 发布:美微网络柠檬视频tv 编辑:程序博客网 时间:2024/05/16 11:52
给一个图,从点1出发,d表示从1出发的最短路,求一种边的权值构造方法使 d(1)
#pragma comment(linker, "/STACK:1024000000,1024000000")#include <stdio.h>#include <queue>#include <map>#include <vector>#include <string>#include <cstring>#include <algorithm>#include <iostream>#include <cstdlib>#include <cctype>#include <set>#include <cmath>using namespace std;typedef long long ll;const int MAXN=1e5+10;int d[MAXN];struct AP{ int to,id;};vector<AP> G[MAXN];int n,m;bool ans[MAXN];bool vis[MAXN];int l[MAXN],r[MAXN];void dfs(int u,int time){ d[u]=time; for(int i=0;i<G[u].size();i++) { int v=G[u][i].to; if(vis[v]) continue; vis[v]=true; ans[G[u][i].id]=true; }}int abbs(int v){ if(v<0) return -v; return v;}int main(){ //freopen("in","r",stdin); int t; cin>>t; while(t--) { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) G[i].clear(); for(int i=0;i<m;i++) { int u,v; scanf("%d%d",&u,&v); l[i]=u,r[i]=v; G[u].push_back((AP){v,i}); } memset(ans,0,sizeof(ans)); memset(vis,0,sizeof(vis)); int s=1,t=n; int x=1; vis[1]=true; d[1]=0; for(int i=0;s<=t;i++) { if(i%2) { if(vis[t]) dfs(t--,x++); } else { if(vis[s]) dfs(s++,x++); } } for(int i=0;i<m;i++) { if(ans[i]) { printf("%d\n",abbs(d[l[i]]-d[r[i]])); } else printf("%d\n",n); } } return 0;}
0 0
- HDU 5385
- hdu-5385
- HDU 5385 The path
- hdu 5385 The path
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- Android编程之LocalBroadcastManager源码详解
- [推荐算法]Pearson Correlation Similarity 的python实现
- The last packet sent successfully to the server was 0 milliseconds ago, The driver has not received
- 韩信点兵
- Android ViewPager无限滑动(支持左右,存在传入数量限制)方式二
- HDU 5385
- 应用程序的makefile编写例程
- 2015.08.13
- foj Problem 1894 志愿者选拔---单调队列
- 读书笔记_高质量程序设计指南C++/C语言_10_文件结构和版式
- linux 设备模型(二 driver)
- 黑马程序员———API之Object、String和Scanner
- 倒立三角形
- noip1997 棋盘 (数列求和)