L题

题目描述
LCR is really an incredible being.
Thinking so, sitting on the plane and looking at the sea, Rikka savours the fantastic journey. A fire never happened. It must be interesting to share it with her mates, and another travel is also fascinating.
But before all, home is the best.
She travels by the JR lines. There are n stations in total, and m public bidirectional railway lines are built among them. Each station belongs to either JR West or JR East. Both JR West and JR East have their own private railways connecting all stations owned by themselves.
Rikka has some through tickets and two types of special passes: ICOCA for JR West and Suica for JR East. She pays a through ticket each time and does one of the following:

· Travel from one terminal to another via a public railway line.
· Travel to any station which has the same owner as the current one, using one of her special passes. A pass can be used for multiple times.

Rikka wonders, for each start station, the sum of the minimal numbers of tickets she needs to pay to reach every possible one of the other stations.
输入描述:
The first line contains two integers n, m~(1 \leq n \leq 10^5, 0 \leq m \leq 10^5)n,m (1≤n≤10
5
,0≤m≤10
5
), the numbers of stations and public railways.

The next line contains n integers A_i~(A_i \in {0,1}, i = 1, 2, \dots, n)A
i

(A
i

∈{0,1},i=1,2,…,n), separated by spaces, describing the owner of each station. A_i = 0A
i

=0 if the station i belongs to JR west, and vice versa.

The following m lines describe all the public railways, each of which contains two integers u, v~(1 \leq u, v \leq n, u \neq v)u,v (1≤u,v≤n,u


=v), representing a bidirectional railway connecting u and v. It is guaranteed that no two public railways connect the same pair of stations, and Rikka is able to travel between every pair of stations. Notice that the private railways are not given directly in the input, and Rikka may have to use her passes rather than traveling only through the public railways.
输出描述:
Output n integers in one line, separated by spaces. The i-th integer is \sum_{j=1}^n D(i, j)∑
j=1
n

D(i,j) , where D(u, v) is the minimal number of tickets needed to travel from u to v.

题意:n个车站,车站分0,1两种属性,同种属性可以直达,不同的属性不能直达。问你在每个站台遍历其他所有站台的总花费。

我们分析了可以知道,其实我们的花费只有三种情况,就是1,2,3。对于所有相同属性的车站我们直接n-1的代价就可以遍历完。其他的看看代码就懂了。

#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e5+50;
int tag[MAXN],in[MAXN];
int main(){int n,m; scanf("%d%d",&n,&m);int o=0,z=0;for(int i=1;i<=n;i++){scanf("%d",&tag[i]);if(tag[i]==0) z++; else o++;}for(int i=0;i<m;i++){int u,v; scanf("%d%d",&u,&v);if(tag[u]!=tag[v]) in[u]++,in[v]++;}int oo=0,zz=0;for(int i=1;i<=n;i++){if(in[i]==0){if(tag[i]==0) zz++;else oo++;}}for(int i=1;i<=n;i++){if(tag[i]==0){if(in[i]>0){int ans=z-1;ans += in[i];ans += (o-in[i])*2;printf("%d ",ans);}else{int ans=z-1;ans += (o-oo)*2+oo*3;printf("%d ",ans);}}else{if(in[i]>0){int ans=o-1;ans += in[i];ans += (z-in[i])*2;printf("%d ",ans);}else{int ans=o-1;ans += (z-zz)*2+zz*3;printf("%d ",ans);}}}return 0;
}

2018EC-Final-Eventual hellip; Journey相关推荐

  1. 2018ec final赛后总结

    这场是今年的最后一场了,比起之前的两场,我准备的也更加认真.从赛前1个月开始,我反思了自己一整年的不足,并发现自己的刷题量实在太少,于是这一个月几乎没怎么上课,每天都在刷题.有限时训练,让自己能适应压 ...

  2. 2018-2019 ACM-ICPC, Asia East Continent Finals题解

    以下所有AC题解程序来自"仙客传奇"团队. A. Exotic - Ancient City 题解链接: 2018 EC-Final 部分题解 (A,J) ABCDEFGIJKL ...

  3. [Ec Final 2018] Eventual … Journey

    题目描述: 又N个车站,M条边,每个车站分为黑白两种 如果两个点颜色一样,可以花1的花费到达,或者两个点有边直接连接. 问每个点可以到达的点的总花费的最小值 题目分析: 互相到达的点花费只有三种可能 ...

  4. L Eventual … Journey

    https://codeforc.es/gym/102056 思路:步数只有1,2,3,判断一下10相连情况: #include <iostream> #include <cstri ...

  5. Plitch for the final Feb 16

    Plitch for the final Feb 16 文章目录 Plitch for the final Feb 16 Introduction Exercise Get in the driver ...

  6. 互动艺术品 - Journey(风之旅人)

    Link: https://informationalmind.appspot.com/2013/02/13/InteractiveArt_Journey.html 大约一个月前无意中看到了一个玩家录 ...

  7. public static final int REMIN_REQUEST_CODE = 0x911 自己的大致理解

    public static final int REMIN_REQUEST_CODE = 0x911; 自己理解为 一个静态常量,也就一个标识,自己目前主要在2个地方常用到 OnActivityRes ...

  8. java内部类的权限符,static介绍、内部类、final、权限修饰符的作用范围,

    static介绍.内部类.final.权限修饰符的作用范围,static 关键字:(可用于修饰方法.变量) static 特点: static是静态修饰符,一般修饰成员变量.被static修饰的属于全 ...

  9. java增加final,Java8增加功能--Effectively final 功能

    java8新增了很多功能,可以大大简化代码,这个系列将会一一辅助代码加以介绍. 局部内部类和匿名内部类访问的局部变量必须由final修饰,java8开始,可以不加final修饰符,由系统默认添加.ja ...

最新文章

  1. Educational Codeforces Round 12 C. Simple Strings 贪心
  2. php 数组 添加元素、删除元素
  3. 如何用RHEL System Role把Postfix安装和配置自动化?
  4. npm 报错: npm ERR! Please try running this command again as root/Administrator.
  5. 如何使用QuickConnect远程访问Synology NAS
  6. 【Jmeter篇】Jmeter分布式调度压测部署
  7. vue写js代码_vue.js弹出式音乐播放器特效代码
  8. Vue学习之监视属性watch
  9. Win8系统如何关闭用户账户控制UAC
  10. python-基于UDP通信的套接字,socketserver模块的使用
  11. 香港科技大学理学院数据建模硕士学位项目MSc DDM 项目介绍×申请指南
  12. 希尔伯特变换(1)-基础理论
  13. 从招聘信息看-数据分析师(数据分析报告)
  14. BCH5月硬分叉,如果做成了支付,会超越BTC吗?
  15. js仿百度文库文档上传页面的分类选择器_第二版
  16. com组件 的劫持_IE首页被劫持跳转问题的解决方案
  17. jzoj 4638. 第三条跑道
  18. vue3 中使用antd UI组件
  19. idm+百度下载助手解决百度网盘限速
  20. 15张超详细的Python学习路线图,纯良心分享,零基础学习宝典

热门文章

  1. CBG 2108班day04学习内容总结
  2. C语言联合体/共用体/union,枚举使用大全
  3. 以太网之生成树与VLAN
  4. 算法 图2 Saving James Bond - Easy Version
  5. 【Django】Django路由urls详解
  6. Django配置默认路由,接受所有请求
  7. python词频统计的方式
  8. matlab中用于数据的标准化处理的zscore函数
  9. 区间估计——置信区间
  10. python--识别图片中的文字