Exemple #1
0
int main() {
  int T;
  scanf("%d", &T);
  for(int kase = 1; kase <= T; kase++) {
    int n, m;
    scanf("%d%d", &n, &m);
    solver.init(n);
    int ub = 0;
    while(m--) {
      int u, v, w;
      scanf("%d%d%d", &u, &v, &w); u--; v--; ub = max(ub, w);
      solver.AddEdge(u, v, w);
    }
    printf("Case #%d: ", kase);
    if(!test(ub+1)) printf("No cycle found.\n");
    else {
      double L = 0, R = ub;
      while(R - L > 1e-3) {
        double M = L + (R-L)/2;
        if(test(M)) R = M; else L = M;
      }
      printf("%.2lf\n", L);
    }
  }
  return 0;
}
Exemple #2
0
main()
{
    int V,E;
    while (scanf("%d%d",&V,&E)==2)
    {
        int u,v,w;
        int max_w=0;
        solver.init(V);
        for (int i=0;i<E;i++)
        {
            scanf("%d%d%d",&u,&v,&w);
            u--,v--;
            solver.AddEdge(u,v,w);
            max_w=max(w,max_w);
        }
        if (test(max_w+1))
        {
            printf("Infinite\n");
            continue;
        }
        else if (!test(1))
        {
            printf("No Solution\n");
            continue;
        }
        int L=0,R=max_w;
        while (L<=R)
        {
            int mid=(L+R)/2;
            if (!test(mid)) R=mid-1;
            else L=mid+1;
        }
        if (!test(L)) L--;
        printf("%d\n",L);
    }
    return 0;
}