void build() { int s = N, t = N + 1; mf.init( N + 2 ); int v, w, c; for( int i = 0; i < M; ++i ) { while( getchar() != '(' ); scanf( "%d", &v ); getchar(); scanf( "%d", &w ); getchar(); scanf( "%d", &c ); mf.insert( v, w, c ); } for( int i = M; i < M + S; ++i ) { while( getchar() != '(' ); scanf( "%d", &w ); getchar(); scanf( "%d", &c ); mf.insert( s, w, c ); } for( int i = M + S; i < M + S + T; ++i ) { while( getchar() != '(' ); scanf( "%d", &v ); getchar(); scanf( "%d", &c ); mf.insert( v, t, c ); } }
void build() { int s = N, t = N + 1; mf.init( N + 2 ); char skip; int v, w, c; for( int i = 0; i < M; ++i ) { cin >> skip >> v >> skip >> w >> skip >> c; mf.insert( v, w, c ); } for( int i = M; i < M + S; ++i ) { cin >> skip >> w >> skip >> c; mf.insert( s, w, c ); } for( int i = M + S; i < M + S + T; ++i ) { cin >> skip >> v >> skip >> c; mf.insert( v, t, c ); } }
int main() { while( scanf( "%d%d", &N, &M ) && N ) { mf.init( N + M + 2 ); for( int i = 1; i <= N; ++i ) { mf.insert( 0, i, 1 ); scanf( "%s", skip ); while( getchar() != '\n' ) { int x; scanf( "%d", &x ); mf.insert( i, N + 1 + x, 1 ); } } st = mf.edges; for( int i = 1; i <= M; ++i ) mf.insert( N + i, N + M + 1, N ); ed = mf.edges; int l = N / M, r = N, m; while( l < r - 1 ) { m = ( l + r ) / 2; if( check( m ) ) r = m; else l = m; } printf( "%d\n", r ); } }
int main() { while(scanf("%d%d%d%d", &N, &M, &A, &B) && N) { mf.init(N); for(int i = 0; i < M; ++i) { int x, y, c; scanf("%d%d%d", &x, &y, &c); x--;y--; mf.insert(x, y, c); mf.insert(y, x, c); } puts(mf.uniQ(A-1, B-1) ? "UNIQUE" : "AMBIGUOUS" ); } }
int main() { while(cin >> N >> M) { if(T++) puts(""); int v, w; double c, m = 0; mf.init(N); for(int i = 0; i < M; ++i) { cin >> v >> w >> c; m = max(m, c); mf.insert(v, w, c); // mf.insert(w, v, c); } double l = 0, r = m; while(r - l > EPS) { m = (l + r) / 2; if(check(m)) r = m; else l = m; } /* for(int i = 0; i < M; ++i) { cout << mf.buf[i].v << ' '; cout << mf.buf[i].w << ' '; cout << mf.buf[i].c << ' '; cout << mf.buf[i].f << endl; } */ //cout << m << endl; memset(B, 0, sizeof(B)); EE.clear(); for(int i = 0; i < M; ++i) { mf.buf[i].c -= m; if(mf.buf[i].c < 0) EE.push_back(i); } dfs(1);puts(""); sort(EE.begin(), EE.end()); EE.resize(unique(EE.begin(), EE.end()) - EE.begin()); cout << EE.size() << endl; for(int i = 0; i < EE.size(); ++i) { if(i) cout << ' '; cout << EE[i] + 1; } } }
bool minCut( double lamda ) { mf.init( V ); now.clear(); double tot = 0.0; for( int i = 0; i < EE.size(); ++i ) { if( EE[i].c > lamda ) mf.insert( EE[i].v-1, EE[i].w-1, EE[i].c - lamda ); else { now.push_back( i + 1 ); tot += ( EE[i].c - lamda ); } } mf.runCut( 0, V - 1 ); eE = mf.getCutE(); for( int i = 0; i < eE.size(); ++i ) { tot += eE[i] -> c; now.push_back( eE[i] - &mf.edges()[0] + 1 ); } sort( now.begin(), now.end() ); ans = now; return tot < 0.0; }