A14826 | MinOr Tree
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Recently, Vlad has been carried away by spanning trees, so his friends, without hesitation, gave him a connected weighted undirected graph of $n$ vertices and $m$ edges for his birthday.
Vlad defined the ority of a spanning tree as the [bitwise OR](https://tiny.cc/bitwise_or) of all its weights, and now he is interested in what is the minimum possible ority that can be achieved by choosing a certain spanning tree. A spanning tree is a connected subgraph of a given graph that does not contain cycles.
In other words, you want to keep $n-1$ edges so that the graph remains connected and the bitwise OR weights of the edges are as small as possible. You have to find the minimum bitwise OR itself.
Vlad defined the ority of a spanning tree as the [bitwise OR](https://tiny.cc/bitwise_or) of all its weights, and now he is interested in what is the minimum possible ority that can be achieved by choosing a certain spanning tree. A spanning tree is a connected subgraph of a given graph that does not contain cycles.
In other words, you want to keep $n-1$ edges so that the graph remains connected and the bitwise OR weights of the edges are as small as possible. You have to find the minimum bitwise OR itself.
输入格式
The first line of the input contains an integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases in the input.
An empty line is written in front of each test case.
This is followed by two numbers $n$ and $m$ ( $3 \le n \le 2 \cdot 10^5, n - 1 \le m \le 2 \cdot 10^5$ ) — the number of vertices and edges of the graph, respectively.
The next $m$ lines contain the description of the edges. Line $i$ contains three numbers $v_i$ , $u_i$ and $w_i$ ( $1 \le v_i, u_i \le n$ , $1 \le w_i \le 10^9$ , $v_i \neq u_i$ ) — the vertices that the edge connects and its weight.
It is guaranteed that the sum $m$ and the sum $n$ over all test cases does not exceed $2 \cdot 10^5$ and each test case contains a connected graph.
An empty line is written in front of each test case.
This is followed by two numbers $n$ and $m$ ( $3 \le n \le 2 \cdot 10^5, n - 1 \le m \le 2 \cdot 10^5$ ) — the number of vertices and edges of the graph, respectively.
The next $m$ lines contain the description of the edges. Line $i$ contains three numbers $v_i$ , $u_i$ and $w_i$ ( $1 \le v_i, u_i \le n$ , $1 \le w_i \le 10^9$ , $v_i \neq u_i$ ) — the vertices that the edge connects and its weight.
It is guaranteed that the sum $m$ and the sum $n$ over all test cases does not exceed $2 \cdot 10^5$ and each test case contains a connected graph.
输出格式
Print $t$ lines, each of which contains the answer to the corresponding set of input data — the minimum possible spanning tree ority.
输入输出样例
输入 #1
3 3 3 1 2 1 2 3 2 1 3 2 5 7 4 2 7 2 5 8 3 4 2 3 2 1 2 4 2 4 1 2 1 2 2 3 4 1 2 1 2 3 2 1 3 3 3 1 4
输出 #1
2 10 3
Graph from the first test case. Ority of this tree equals to 2 or 2 = 2 and it's minimal. Without excluding edge with weight $1$ ority is 1 or 2 = 3.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted