这是什么鬼OJ啊都没见过害的我还交错语言CE了一发摔
想着懒得重写了直接把上一题的dij改了改就交了 然后RE
反应过来这题有负环 想着怎么标记负环同时不直接结束spfa
看了别人的代码感叹了一下我还是太弱 多学习吧 =.=
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <queue>
#include <vector>
#include <set>
#include <algorithm>
#define INF 0x3F3F3F3F
using namespace std; int busy[], val[][];
int t, n, m, q, dist[];
bool cir[]; void spfa(int s)
{
int time[];
bool vis[];
queue<int> q;
memset(vis, , sizeof vis);
memset(time, , sizeof time);
memset(dist, 0x3f, sizeof dist); dist[s] = ;
vis[s] = true;
q.push(s);
while(!q.empty()){
int u = q.front();
q.pop();
vis[u] = false;
if(cir[u]) continue;
for(int i = ; i <= n; i++){
if(dist[i] > dist[u] + val[u][i]){
dist[i] = dist[u] + val[u][i];
if(!vis[i]){
q.push(i);
if(time[i]++ > n) cir[i] = true;
}
}
}
}
} int main()
{
scanf("%d", &t);
for(int i = ; i <= t; i++){
memset(val, 0x3f, sizeof val);
memset(cir, , sizeof cir); scanf("%d", &n);
for(int j = ; j <= n; j++){
scanf("%d", &busy[j]);
} scanf("%d", &m);
for(int j = ; j <= m; j++){
int s, d;
scanf("%d%d", &s, &d);
val[s][d] = (int)pow(busy[d] - busy[s], );
} spfa();
scanf("%d", &q);
printf("Case %d:\n", i);
while(q--){
int d;
scanf("%d", &d);
if(cir[d] || dist[d] < || dist[d] == INF) puts("?");
else printf("%d\n", dist[d]);
}
}
return ;
}