这次Div.2比之前我打的有些要难啊,前三道题就耗了好多时间,D题干脆摆烂了。。。

还是太逊了

对于一个\(x\),有\(x|y_i=z_i\),那么我们设\(num[x]=z_1\)&\(z_2\)&\(z_3\)....

若\(z_i\)的第\(pos\)位为0,则说明\(x\)与\(y_i\)的第\(pos\)位一定为0;若\(z_i\)的第\(pos\)位为0,则说明\(x\)与\(y_i\)第pos至少 有一个为1,即\(x\)的第\(pos\)位可能为1,\(y_i\)的第\(pos\)位可能为1

所以,对于初始的\(num[x]\),它就是第\(x\)个数的所有答案中最大的

既然答案要求字典序最小,那么遍历第一个数到最后一个数,将当前数记为\(x\),将所有与\(x\)有题目给定的关系的\(y\)与\(z\)都遍历一遍,记 \(t|=z_i\)&(~\(num[y_i]\))

\(z_i\)&(~\(num[y_i]\))显然意味着在当前这个关系中,\(x\)必须取到的1

所以\(t|=z_i\)&(~\(num[y_i]\))也就意味这对于\(x\)的所有关系,\(x\)必须取的数

前文说了对于初始的\(num[x]\),它是第\(x\)个数的所有答案中最大的,所以这时求出的\(t\)也一定 是第一个数最小的答案

再将\(num[x]\)更新为\(t\),继续上述过程,得到的就是字典序最小的答案

#include<bits/stdc++.h>
#define pr pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e5+5,M=2e5+5;
int n,q,num[N];
vector<pr> cdt[N];
int main(){
scanf("%d%d",&n,&q);
for(int i=1;i<=n;++i) num[i]=(1<<30)-1;
for(int i=1,x,y,z;i<=q;++i){
scanf("%d%d%d",&x,&y,&z);
num[x]&=z,num[y]&=z;
cdt[x].push_back(pr(y,z));
cdt[y].push_back(pr(x,z));
}
for(int i=1;i<=n;++i){
int t=0;
for(int j=0;j<cdt[i].size();++j){
int x=cdt[i][j].fi,s=cdt[i][j].se;
t|=(s&(~num[x]));
if(x==i){ t=s; break; }
}
printf("%d ",(num[i]=t));
}
return 0;
}

[Codeforces Round #816 (Div. 2)] D. 2+ doors的更多相关文章

  1. Codeforces Round #549 (Div. 2)A. The Doors

    A. The Doors time limit per test 1 second memory limit per test 256 megabytes input standard input o ...

  2. Codeforces Round #816 (Div. 2)/CodeForces1715

    CodeForces1715 Crossmarket 解析: 题目大意 有一个 \(n \times m\) 的空间,Stanley 需要从左上角到右下角:Megan 则需要从左下角到右上角.两人可以 ...

  3. Codeforces Round #297 (Div. 2)A. Vitaliy and Pie 水题

    Codeforces Round #297 (Div. 2)A. Vitaliy and Pie Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  ...

  4. Codeforces Round #531 (Div. 3) ABCDEF题解

    Codeforces Round #531 (Div. 3) 题目总链接:https://codeforces.com/contest/1102 A. Integer Sequence Dividin ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. Silky微服务框架之模块

    模块的定义 Silky是一个包括多个nuget包构成的模块化的框架,每个模块将程序划分为一个个小的结构,在这个结构中有着自己的逻辑代码和自己的作用域,不会影响到其他的结构. 模块类 一般地,一个模块的 ...

  2. Codeforces Round #827 (Div. 4) A-G

    比赛链接 A 题解 知识点:模拟. 时间复杂度 \(O(1)\) 空间复杂度 \(O(1)\) 代码 #include <bits/stdc++.h> #define ll long lo ...

  3. linux-web基础

    web基础 [TOC] 网上冲浪 网上冲浪:在Internet互联网上获取各种信息,进行工作.娱乐,在英文中上网是" surfing the internet",因"su ...

  4. rocky二进制安装mysql8.0

    (ubuntu的有点问题) 点击查看代码 #!/bin/bash Version=`cat /etc/os-release |awk -F'"| ' '/^NAME/{print $2}'` ...

  5. Day13 note

    super注意点: 1.super调用父类的构造方法,必须在构造方法的第一行 2.super必须只能出现在子类的方法或者构造方法中 3.super和this不能同时调用构造方法对比this: 1.代表 ...

  6. promise 的串行执行

    function pri (num) {   return new Promise((resolve,reject) => {     console.log('开始'+num)     res ...

  7. 【翻译】Thymeleaf – Spring Security集成模块

    原文链接:Thymeleaf - Spring Security integration modules 来源:thymeleaf/thymeleaf-extras-springsecurity自述文 ...

  8. nginx日志切割并备份

    [root@lecode-pre55 bin]# cat nginx-log.sh #!bin/bash #auther:ansheng #desc: nginx日志备份,注意脚本中文件的路径. #备 ...

  9. 2022春每日一题:Day 37

    题目:[USACO14FEB]Auto-complete S 字典树套路题,字典树优化剪枝,加个cnt标记即可 代码: #include <cstdio> #include <cst ...

  10. Chrome 103支持使用本地字体,纯前端导出PDF优化

    在前端导出PDF,解决中文乱码一直是一个头疼的问题.要解决这个问题,需要将ttf等字体文件内容注册到页面PDF生成器中.但是之前网页是没有权限直接获取客户机器字体文件,这时就需要从服务器下载字体文件或 ...