Description
A crime has been comitted: a load of grain has been taken from the barn by one of FJ's cows. FJ is trying to determine which of his C (1 <= C <= 100) cows is the culprit. Fortunately, a passing satellite took an image of his farm M (1 <= M <= 70000) seconds before the crime took place, giving the location of all of the cows. He wants to know which cows had time to get to the barn to steal the grain. Farmer John's farm comprises F (1 <= F <= 500) fields numbered 1..F and connected by P (1 <= P <= 1,000) bidirectional paths whose traversal time is in the range 1..70000 seconds (cows walk very slowly). Field 1 contains the barn. It takes no time to travel within a field (switch paths). Given the layout of Farmer John's farm and the location of each cow when the satellite flew over, determine set of cows who could be guilty. NOTE: Do not declare a variable named exactly 'time'. This will reference the system call and never give you the results you really want.
Input
* Line 1: Four space-separated integers: F, P, C, and M * Lines 2..P+1: Three space-separated integers describing a path: F1, F2, and T. The path connects F1 and F2 and requires T seconds to traverse. * Lines P+2..P+C+1: One integer per line, the location of a cow. The first line gives the field number of cow 1, the second of cow 2, etc.
第1行输入四个整数F,只C,和M;
接下来P行每行三个整数描述一条路,起点终点和通过时间.
Output
* Line 1: A single integer N, the number of cows that could be guilty of the crime.
* Lines 2..N+1: A single cow number on each line that is one of the cows that could be guilty of the crime. The list must be in ascending order.
Sample Input
1 4 2
1 2 1
2 3 6
3 5 5
5 4 6
1 7 9
1
4
5
3
7
Sample Output
1
2
3
4
HINT
因为数据实在太弱,各种最短路都能过……
写了个floyd
#include<cstring> #include<cstdio> inline int read() { int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline int min(int a,int b) {if(a<b)return a;else return b;} int n,m,c,t,len; int dist[1001][1001]; int ans[1001]; int main() { n=read(); m=read(); c=read(); t=read(); memset(dist,127/3,sizeof(dist)); for (int i=1;i<=n;i++)dist[i][i]=0; for(int i=1;i<=m;i++) { int x=read(),y=read(),z=read(); if (z<=t) { dist[x][y]=min(dist[x][y],z); dist[y][x]=dist[x][y]; } } for (int k=1;k<=n;k++) for (int i=1;i<=n;i++) for (int j=1;j<=n;j++) if (i!=j) if (dist[i][k]+dist[k][j]<dist[i][j]) dist[i][j]=dist[i][k]+dist[k][j]; for (int i=1;i<=c;i++) { int x=read(); if (dist[x][1]>t) continue; ans[++len]=i; } for (int i=1;i<len;i++) for (int j=i+1;j<=len;j++) if(ans[i]>ans[j]) { int t=ans[i]; ans[i]=ans[j]; ans[j]=t; } printf("%d ",len); for (int i=1;i<=len;i++) printf("%d ",ans[i]); }