@bob 1621 ybt 差一个点?? #include<bits/stdc++.h> using namespace std; const int inf=0x3f3f3f3f; typedef long long ll; int n, l, d; ll s[100005], vis[100005], cnt[100005], ccnt; int head[100005]; inline int read() { int x=0; char ch, c; ch = getchar(); c = ch; while(ch<'0'||ch>'9') c = ch, ch = getchar(); while(ch >= '0' && ch <= '9') { x = x*10+ch-'0'; ch = getchar(); } return x; } struct T { int v, w, nxt; }e[100005*3]; void add(int u,int v,int w) { e[++ccnt].v = v; e[ccnt].nxt = head[u]; e[ccnt].w = w; head[u] = ccnt; } bool SPFA() { memset(vis,0,sizeof(vis)); memset(s,inf,sizeof(s)); memset(cnt,0,sizeof(cnt)); queue<int> q; q.push(1); s[1] = 0; vis[1] = 1; while(q.size()) { int u = q.front(); q.pop(); cnt[u]++;///////////》》》》》》》》》》》》加再判,判再加?? if(cnt[u]>n) return false; for(int i=head[u];i;i=e[i].nxt) { int v = e[i].v, w = e[i].w; if(s[v]>s[u]+w) { s[v] = s[u]+w; if(!vis[v]) { vis[v] = 1; q.push(v); } } } vis[u] = 0; } return true; } int main() { n = read(); l = read(); d = read(); for(int i=1;i<=l;i++) { int a, b, c; cin>>a>>b>>c; add(a,b,c);///a,b, b, a?????? } for(int i=1;i<=d;i++) { int a, b, c; cin>>a>>b>>c; add(b,a,-c); } if(SPFA()) { if(s[n]==inf) cout<<"-2\n"; else cout<<s[n]<<endl; } else cout<<"-1\n"; return 0; } ///>>>>>若以0始是否应寻一边0->i, i属于[0,n]?????????