BZOJ 3890 Usaco2015 Jan Meeting Time 拓扑排序
2015-03-06 13:04
351 查看
题目大意:给定一张拓扑图,每条边有两个边权,求两条1到n的路径,第一条用边权1,第二条用边权2,要求两条路径长度相等且最短
注意到边权<=100,n<=100,因此一条路径的长度最大只有10000
拓扑序DP一下用bitset做就行了
注意到边权<=100,n<=100,因此一条路径的长度最大只有10000
拓扑序DP一下用bitset做就行了
#include <bitset> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define M 110 using namespace std; struct abcd{ int to,next; int f1,f2; }table[5050]; int head[M],tot; int n,m,degree[M]; bitset<10100> f[M],g[M]; void Add(int x,int y,int z1,int z2) { degree[y]++; table[++tot].to=y; table[tot].f1=z1; table[tot].f2=z2; table[tot].next=head[x]; head[x]=tot; } int main() { int i,x,y,z1,z2; cin>>n>>m; for(i=1;i<=m;i++) { scanf("%d%d%d%d",&x,&y,&z1,&z2); Add(x,y,z1,z2); } static int q[M],r,h; f[1][0]=g[1][0]=true; for(i=1;i<=n;i++) if(!degree[i]) q[++r]=i; while(r!=h) { int x=q[++h]; for(i=head[x];i;i=table[i].next) { f[table[i].to]|=f[x]<<table[i].f1; g[table[i].to]|=g[x]<<table[i].f2; if(!--degree[table[i].to]) q[++r]=table[i].to; } } for(i=0;i<=10000;i++) if(f [i]&&g [i]) return cout<<i<<endl,0; return cout<<"IMPOSSIBLE"<<endl,0; }
相关文章推荐
- BZOJ 3890 Usaco2015 Jan Meeting Time 拓扑图DP
- bzoj 3890: [Usaco2015 Jan]Meeting Time bfs
- 【BZOJ3890】【Usaco2015 Jan】Meeting Time 拓扑图简单DP
- bzoj3890 [Usaco2015 Jan]Meeting Time
- BZOJ3890 [Usaco2015 Jan]Meeting Time K短路 Astar || 拓扑DP
- bzoj3890 [Usaco2015 Jan]Meeting Time [spfa + A*]
- 【bzoj3886】[Usaco2015 Jan]Moovie Mooving 状态压缩dp+二分
- BZOJ[3887][Usaco2015 Jan]Grass Cownoisseur Tarjan+拓扑排序
- 3890: [Usaco2015 Jan]Meeting Time( dp )
- [BZOJ3887][Usaco2015 Jan]Grass Cownoisseur(tarjan+spfa)
- BZOJ 3887 [Usaco2015 Jan]Grass Cownoisseur
- bzoj 3889: [Usaco2015 Jan]Cow Routing SPFA
- 【BZOJ3887】【Usaco2015 Jan】Grass Cownoisseur Tarjan+Spfa
- BZOJ 【BZOJ3887】【Usaco2015 Jan】Grass Cownoisseur
- 【bzoj3889】[Usaco2015 Jan]Cow Routing 最短路
- 图例练习题:【BZOJ3889】【Usaco2015 Jan】Cow Routing 双键值最短路
- bzoj3888【Usaco2015 Jan】Stampede
- 【BZOJ3889】【Usaco2015 Jan】Cow Routing 双键值最短路
- [BZOJ 3888] [Usaco2015 Jan] Stampede 【线段树】
- 【BZOJ3885】【Usaco2015 Jan】Cow Rectangles 某奇怪的最大子矩形