int main() { int n, i, j; scanf("%d", &n); while(n--) { int x, y; int map[51][51] = {}; int node[51] = {}; MakeInit(50); while(scanf("%d %d", &x, &y) == 2) { if(x == 0 && y == 0) break; map[x][y] = 1; map[y][x] = 1; node[x] = 1; node[y] = 1; Union(x, y); } int tn = 0, tm = 0; for(i = 0; i <= 50; i++) tn += node[i]; for(i = 0; i <= 50; i++) { for(j = 0; j <= 50; j++) tm += map[i][j]; } tm /= 2; int max = 0; for(i = 0; i <= 50; i++) max = Rank[i] > max ? Rank[i] : max; if(max == tn && tn-1 == tm) puts("Yes"); else puts("No"); } return 0; }
int main() { int N, K, M, a, b, c, flag = 0; while(scanf("%d", &N) == 1) { int sum = 0, i, j; for(i = 1; i < N; i++) { scanf("%d %d %d", &a, &b, &c); sum += c; } if(flag) puts(""); flag = 1; printf("%d\n", sum); scanf("%d", &K); for(i = 0; i < K; i++) scanf("%d %d %d", &D[i].x, &D[i].y, &D[i].v); scanf("%d", &M); for(i = 0, j = K; i < M; i++, j++) scanf("%d %d %d", &D[j].x, &D[j].y, &D[j].v); M = K+M, sum = 0; qsort(D, M, sizeof(Link), cmp); MakeInit(N); for(i = 0; i < M; i++) sum += Union(D[i].x, D[i].y) * D[i].v; printf("%d\n", sum); } return 0; }
// // make_var // static SourceExpression::Pointer make_var(SourceTokenizerC *in, SourceContext *context, LinkageSpecifier linkSpec, SourcePosition const &pos, std::string const &nameSrc, VariableType::Reference type, StoreData const &store, bool externDef) { SourceExpression::Pointer initExpr; SourceVariable::Pointer var; ObjectExpression::Pointer addr; if (in->peekType(SourceTokenC::TT_AT)) { in->get(); addr = SourceExpressionDS::make_prefix(in, context)->makeObject(); } // Generate object name. std::string nameObj; switch (linkSpec) { case LINKAGE_INTERN: nameObj = context->getLabel() + nameSrc; break; case LINKAGE_ACS: nameObj = nameSrc; break; case LINKAGE_C: nameObj = "_" + nameSrc; break; case LINKAGE_CPP: case LINKAGE_DS: nameObj = context->getLabelNamespace() + nameSrc; break; } // Generate expression (unless final type is determined later). SourceExpression::Pointer expr; if(!is_array_length_zero(type) && !is_void(type) && !is_autoptr(type)) expr = add_var(context, linkSpec, pos, nameSrc, nameObj, type, store, addr, externDef, var); // Variable initialization. (But not for external declaration.) if (!externDef && in->peekType(SourceTokenC::TT_EQUALS)) { SourceExpression::Pointer initSrc; ObjectExpression::Pointer initObj; in->get(SourceTokenC::TT_EQUALS); initSrc = SourceExpressionDS::make_assignment(in, context); // Automatic type. if (is_void(type)) { if (type->getBasicType() == VariableType::BT_VOID) type = initSrc->getType(); else { VariableType::Reference initSrcType = initSrc->getType(); if (initSrcType->getBasicType() != VariableType::BT_BLOCK) Error_P("expected BT_BLOCK"); type = get_void(type, initSrcType); type = get_array_length(type, initSrcType); } expr = add_var(context, linkSpec, pos, nameSrc, nameObj, type, store, addr, externDef, var); } // Initializer-determined array length. else if(is_array_length_zero(type)) { VariableType::Reference initSrcType = initSrc->getType(); if(initSrcType->getBasicType() == VariableType::BT_BLOCK) { type = get_array_length(type, initSrcType); } else if(initSrcType->getBasicType() == VariableType::BT_STR) { std::string initStr = initSrc->makeObject()->resolveString(); type = type->getReturn()->getArray(initStr.size()); initSrcType = initSrcType->getReturn()->getArray(initStr.size()); initSrc = SourceExpression:: create_value_cast_force(initSrc, initSrcType, context, pos); } else Error_P("expected block or string"); expr = add_var(context, linkSpec, pos, nameSrc, nameObj, type, store, addr, externDef, var); } // Initializer-determined storage. else if(is_autoptr(type)) { VariableType::Reference initSrcType = initSrc->getType(); if(initSrcType->getBasicType() == VariableType::BT_PTR) { initSrcType = initSrcType->getReturn(); type = type->getReturn() ->setStorage(initSrcType->getStoreType(), initSrcType->getStoreArea()) ->getPointer(); } expr = add_var(context, linkSpec, pos, nameSrc, nameObj, type, store, addr, externDef, var); } // Cast initSrc to the new object's type. initSrc = SourceExpression:: create_value_cast_implicit(initSrc, type, context, pos); // Generate initObj here in case one of the above rules alters initSrc. if(initSrc->canMakeObject()) initObj = initSrc->makeObject(); // Generate expression to set variable. SourceExpression::Pointer exprSet = SourceExpression:: create_binary_assign_const(expr, initSrc, context, pos); switch (store.type) { case STORE_MAPREGISTER: if(!initObj || Target == TARGET_Hexen) goto case_init; if(!ObjectData::Register::InitMap(nameObj, type, initObj)) goto case_init; break; case STORE_MAPARRAY: if(!initObj) goto case_init; if(!ObjectData::ArrayVar::InitMap(nameObj, type, initObj)) goto case_init; break; case STORE_WORLDARRAY: case STORE_GLOBALARRAY: case STORE_STATIC: case_init: { if(!initExpr) initExpr = MakeInit(context, pos, var, nameObj, store, false); // Generate expression of value if initialized. SourceExpression::Pointer initVal = SourceExpression:: create_value_int(1, context, pos); // Generate expression to set flag. SourceExpression::Pointer initSet = SourceExpression:: create_binary_assign(initExpr, initVal, context, pos); // Generate expression to check if initialized. SourceExpression::Pointer initChk = SourceExpression:: create_branch_not(initExpr, context, pos); // Generate expression to set variable and flag. SourceExpression::Vector initBothVector; initBothVector.push_back(exprSet); initBothVector.push_back(initSet); SourceExpression::Pointer initBoth = SourceExpression:: create_value_block(initBothVector, context, pos); // Generate expression to conditionally set variable and flag. expr = SourceExpression:: create_branch_if(initChk, initBoth, context, pos); } break; default: expr = exprSet; break; } } // If not done yet, add var now. if (!expr) expr = add_var(context, linkSpec, pos, nameSrc, nameObj, type, store, addr, externDef, var); // Need to always generate the init var for array storage. if((store.type == STORE_MAPARRAY || store.type == STORE_WORLDARRAY || store.type == STORE_GLOBALARRAY) && !initExpr) { initExpr = MakeInit(context, pos, var, nameObj, store, externDef); } return expr; }