标签:NPU pac turn rip ble pos ems als includes
http://acm.hdu.edu.cn/showproblem.php?pid=1534
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2196 Accepted Submission(s): 994
Special Judge
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<queue> 5 using namespace std; 6 struct edge{ 7 int to; 8 int next; 9 int len; 10 }qwq[100005]; 11 queue<int>pq; 12 int edge_cnt=0, n,t[10005],head[100005],in[100005],stk[100005],dist[100005]; 13 bool spfa() 14 { 15 while(!pq.empty()) 16 { 17 pq.pop(); 18 } 19 pq.push(0); 20 in[0]++; 21 stk[0]=1; 22 while(!pq.empty()) 23 { 24 int qaq=pq.front();pq.pop(); 25 stk[qaq]=0; 26 for(int i = head[qaq];i!=-1;i=qwq[i].next) 27 { 28 int v=qwq[i].to; 29 if(dist[v]<dist[qaq]+qwq[i].len) 30 { 31 dist[v]=dist[qaq]+qwq[i].len; 32 if(!stk[v]) 33 { 34 pq.push(v); 35 in[v]++; 36 stk[v]=1; 37 if(in[v]>n+1){ 38 return false; 39 } 40 } 41 } 42 } 43 } 44 return true; 45 } 46 void add(int x,int y,int z) 47 { 48 qwq[edge_cnt].to=y; 49 qwq[edge_cnt].next=head[x]; 50 qwq[edge_cnt].len=z; 51 head[x]=edge_cnt++; 52 } 53 int main() 54 { 55 scanf("%d",&n); 56 int case1=1; 57 while(n) 58 { 59 memset(head,-1,sizeof(head)); 60 memset(dist,-1,sizeof(dist)); 61 dist[0]=0; 62 memset(in,0,sizeof(in)); 63 memset(stk,0,sizeof(stk)); 64 edge_cnt=0; 65 for(int i = 1 ;i <= n ; i++) 66 { 67 scanf("%d",&t[i]); 68 } 69 char ss[50]; 70 int a,c; 71 scanf("%s",ss); 72 while(ss[0]!=‘#‘)//FAS, FAF, SAF and SAS. 73 { 74 scanf("%d%d",&a,&c); 75 if(ss[0]==‘S‘) 76 { 77 if(ss[2]==‘S‘) 78 { 79 add(c,a,0); 80 // cout << c << a << "0\n"; 81 //cout << ss[6]<<" "<<ss[4]-‘0‘ << "0" <<endl; 82 } 83 else 84 { 85 add(c,a,t[c]); 86 // cout << c << a <<t[c]<<endl; 87 // cout << ss[6]<<" "<<ss[4]-‘0‘ << t[ss[6]-‘0‘] <<endl; 88 } 89 } 90 else 91 { 92 if(ss[2]==‘S‘) 93 { 94 add(c,a,-t[a]); 95 //cout << c << a <<-t[a]<<endl; 96 // cout << ss[6]<<" "<<ss[4]-‘0‘ << -t[ss[4]-‘0‘] <<endl; 97 } 98 else 99 { 100 add(c,a,-t[a]+t[c]); 101 // cout << c<<a <<-t[a]+t[c]<<endl; 102 //cout << ss[6]<<" "<<ss[4]-‘0‘ << -t[ss[4]-‘0‘]+t[ss[6]-‘0‘] <<endl; 103 } 104 } 105 for(int i = 1 ; i <= n ; i++) 106 { 107 add(0,i,0); 108 } 109 scanf("%s",ss); 110 } 111 printf("Case %d:\n",case1++); 112 if(!spfa()) 113 printf("impossible\n"); 114 else 115 for(int i = 1 ; i <= n ;i++) 116 { 117 printf("%d %d\n",i,dist[i]); 118 } 119 printf("\n"); 120 scanf("%d",&n); 121 } 122 return 0; 123 }
标签:NPU pac turn rip ble pos ems als includes
原文地址:https://www.cnblogs.com/MekakuCityActor/p/9028207.html