zoukankan      html  css  js  c++  java
  • [ICPC2018西安L] Eventual … Journey

    [ICPC2018西安L] Eventual … Journey - 结论

    Description

    N个车站,M条边,每个车站分为黑白两种,如果两个点颜色一样,可以花1的花费到达,或者两个点有边直接连接,问每个点可以到达的点的总花费的最小值

    Solution

    直接相连或者同类代价为 1,两点度数都为 0 代价为 3,其它情况代价为 2

    #include <bits/stdc++.h>
    using namespace std;
    
    #define int long long
    const int N = 1e5 + 5;
    
    int n, m, a[N], c[2], d[2];
    vector<int> g[N];
    
    signed main()
    {
        ios::sync_with_stdio(false);
        cin >> n >> m;
        for (int i = 1; i <= n; i++)
            cin >> a[i];
        for (int i = 1; i <= m; i++)
        {
            int u, v;
            cin >> u >> v;
            if (a[u] == a[v])
                continue;
            g[u].push_back(v);
            g[v].push_back(u);
        }
    
        for (int i = 1; i <= n; i++)
            c[a[i]]++;
    
        for (int i = 1; i <= n; i++)
            if (g[i].size() == 0)
                d[a[i]]++;
        if (m == 0)
        {
            for (int i = 1; i <= n; i++)
                cout << n - 1 << " ";
            return 0;
        }
    
        for (int i = 1; i <= n; i++)
        {
            if (g[i].size() > 0)
            {
                cout << n - 1 + c[1 - a[i]] - g[i].size() << " ";
            }
            else
            {
                cout << n - 1 + c[1 - a[i]] + d[1 - a[i]] << " ";
            }
        }
    }
    
  • 相关阅读:
    STM32 端口复用配置
    stm32 新建文件记得添加到工程
    keil解决SYSTEMsysstm32f10x.h(298): error: #67: expected a "}"
    解决Keil复制中文乱码
    STM32 MPU6050 源码
    STM32 PWM输出
    STM32定时器
    STM32 看门狗操作姿势
    开课博客
    第二周学习进度
  • 原文地址:https://www.cnblogs.com/mollnn/p/14591255.html
Copyright © 2011-2022 走看看