- Time: 2016-04-13-23:48:46
- Topic number: [2016-04-13][poj][1860][currency Exchange]
- The main idea: Currency exchange, ask the last can be changed by the way make money more,
- Analysis:
- Direct SPFA Determine if there is a ring, and if so, it can add value indefinitely.
- If there is no positive ring, then directly determine whether the final d[s] is greater than the initial value
#include<cstdio>
#include<vector>
#include<cstring>
#include<queue>
using namespace std;
const int maxn = 100 + 10;
struct Edge{
int ; double c R
edge ( int _v = 0 double _c = 0 , Span class= "KWD" >double _r = Span class= "lit" >0 ): v ( _v ), c ( _c r ( _r Span class= "pun") {}
};
vector<Edge> e[maxn];
void ini(int n ){
for(int i = 0 ; i <= n ; ++i){
e[i].clear();
}
}
void addedge(int u,int v,double c,double r){
e[u].push_back(Edge(v,c,r));
}
int cnt[maxn];double d[maxn];
bool spfa(int s,int n,double v){
for ( int i = 0 ; I <= n ++ i ) D [ i = 0
d[s] = v;
queue<int> q;q.push(s);
memset(cnt, 0 , sizeof(cnt));
cnt[s] = 1;
while(!q.empty()){
int u = q.front();
q.pop();
for ( int i = 0 ; I < e [ u . size i
int v = e [ u ][ i . v
if ( d [ v < ( d [ u - e [ u ][ i c * e [ u ][ i r
D [v ] = Span class= "PLN" > ( d [ u - e [ u ][ i c * e [ u ][ i r
q.push(v);
if(++cnt[v] > n) return true;
}
}
}
return d[s] > v;
}
int main(){
int n,m,s;
double v;
scanf("%d%d%d%lf",&n,&m,&s,&v);
for ( int i = 0 ; I < m ++ i ) {
int b double rab cab Span class= "pun", rba CBA Span class= "pun";
scanf("%d%d%lf%lf%lf%lf",&a,&b,&Rab,&Cab,&Rba,&Cba);
addedge(a,b,Cab,Rab);
addedge(b,a,Cba,Rba);
}
puts(spfa(s,n,v)?"YES":"NO");
return 0;
}
From for notes (Wiz)
[2016-04-13] [POJ] [1860] [Currency Exchange]