标签:des style blog http color os io java ar
5 3 7 3 8 10 3 6 8 1 1 3 1 10 11 1
6
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <cmath> 5 #include <algorithm> 6 #include <climits> 7 #include <vector> 8 #include <queue> 9 #include <cstdlib> 10 #include <string> 11 #include <set> 12 #include <stack> 13 #define LL long long 14 #define pii pair<int,int> 15 #define INF 0x3f3f3f3f 16 using namespace std; 17 const int maxn = 50010; 18 struct arc{ 19 int to,w,next; 20 arc(int x = 0,int y = 0,int z = 0){ 21 to = x; 22 w = y; 23 next = z; 24 } 25 }; 26 int n,tot,head[maxn],theMin,theMax,d[maxn]; 27 arc e[maxn<<2]; 28 int q[maxn<<4],he,tail; 29 bool in[maxn]; 30 void add(int u,int v,int w){ 31 e[tot] = arc(v,w,head[u]); 32 head[u] = tot++; 33 } 34 int spfa(){ 35 for(int i = theMin; i <= theMax; i++){ 36 in[i] = false; 37 d[i] = -INF; 38 } 39 d[theMin] = 0; 40 he = tail = 0; 41 q[tail++] = theMin; 42 while(he < tail){ 43 int u = q[he++]; 44 in[u] = false; 45 for(int i = head[u]; ~i; i = e[i].next){ 46 if(d[e[i].to] < d[u]+e[i].w){ 47 d[e[i].to] = d[u]+e[i].w; 48 if(!in[e[i].to]){ 49 in[e[i].to] = true; 50 q[tail++] = e[i].to; 51 } 52 } 53 } 54 } 55 return d[theMax]; 56 } 57 int main() { 58 int u,v,w; 59 while(~scanf("%d",&n)){ 60 memset(head,-1,sizeof(head)); 61 theMin = INF; 62 theMax = -INF; 63 for(int i = tot = 0; i < n; i++){ 64 scanf("%d %d %d",&u,&v,&w); 65 add(u,v+1,w); 66 theMin = min(theMin,u); 67 theMax = max(theMax,v+1); 68 } 69 for(int i = theMin; i < theMax; i++){ 70 add(i,i+1,0); 71 add(i+1,i,-1); 72 } 73 printf("%d\n",spfa()); 74 } 75 return 0; 76 }
标签:des style blog http color os io java ar
原文地址:http://www.cnblogs.com/crackpotisback/p/3961180.html