USACO 到底考什么?2027 赛季 USACO 分级备战指南来了!

USACO早已不是单纯考察“会不会写快排”或“背不背模板”的传统编程赛。2025–2026 赛季起,USACO 正式完成从“算法知识测试”向“综合计算思维能力评估”的转型。

本文将系统解析 USACO 的四大核心能力、近年规则重大变革、各组别考查重点及 2027 赛季精准备考路径,助你用真实实力,在公平而严苛的新赛制中稳步晋级。

一、USACO 到底考什么?四大核心能力

USACO 不再只看“答案对不对”,而是评估你如何思考、如何实现、如何应对失败:

能力维度 考察内容 典型表现
1. 结构化思维 能否将模糊现实问题 → 清晰可计算模型 能快速识别“这是图论问题”“需离散化处理”
2. 算法选择能力 在时间压力下匹配最优解法 面对10⁶数据量,果断放弃暴力,选用线段树或前缀和
3. 代码稳定性 写出鲁棒、无边界错误、内存安全的程序 处理空输入、极端值、重复操作仍能通过所有测试点
4. 调试能力 快速定位逻辑/边界/性能错误 10分钟内发现“数组越界”或“递归爆栈”

二、2025–2026 赛季 vs 往年:六大规则变革

项目 2024 及以前 2025–2026 新规 影响
比赛结构 4场线上月赛 3场月赛 + 1场监考制 US Open Open 含金量提升,成选拔关键
成绩认证 Gold/Platinum 需在开赛15分钟内启动才算“认证成绩” 防止代打,确保成绩真实有效
晋级规则 单场可连升多级(如 Bronze→Silver→Gold) 每场最多晋级一级 降低偶然性,强调稳定发挥
训练营选拔 综合全年成绩 需 2–3 场认证成绩 + US Open 表现 高阶选手必须多次证明自己
AI 工具 无明确限制 严禁 ChatGPT、GitHub Copilot 等生成式 AI 违规=永久封号+通报学校
VPN/IP 规则 无要求 美国选手须用注册地 IP,禁用代理 提升公平性,防止跨区作弊

三、2027 赛季 USACO 分级备战指南

铜组(Bronze)——入门筑基

目标:稳过 700 分,顺利晋级 Silver

核心任务:

掌握 C++ 或 Python 基础语法(推荐 C++,效率更高);

熟练使用 循环、条件、数组、字符串、简单模拟;

学会 优化暴力解法(如减少嵌套循环、提前终止);

刷透 USACO 官方 Guide 铜组题库(约 30–50 题);

模拟 4 小时完整比赛流程,避免因不熟悉提交系统丢分。

避坑:不要死磕难题,确保前两题 100% 正确。

银组(Silver)——算法启蒙

目标:摆脱暴力,掌握基础算法灵活应用

核心任务:

系统学习四大支柱:

贪心策略(活动选择、区间调度)

搜索(DFS/BFS,状态表示)

二分查找(答案/位置二分)

前缀和 / 差分(高效区间操作)

强化 图论建模能力:最短路(Floyd/Dijkstra)、拓扑排序;

学会 从样例反推规律,培养构造思维;

每周完成 2–3 道 Silver 真题,限时 2 小时。

关键突破:理解“为什么用这个算法”,而非“怎么抄模板”。

金组(Gold)——高阶融合

目标:掌握高级算法,应对大规模数据

核心任务:

重点攻克:

动态规划:区间 DP、树形 DP、状态压缩

图论进阶:最小生成树(Kruskal/Prim)、强连通分量

数据结构:树状数组、线段树(支持区间更新)

常数优化训练:避免 vector 频繁 resize、IO 优化(scanf/printf);

严格按认证规则模拟:开赛 15 分钟内启动,4 小时内提交;

刷近 5 年 Gold 真题,总结“套路题”与“创新题”差异。

晋级关键:第三题部分分也要拿,Gold 常靠“2.5题”晋级。

铂金组(Platinum)——顶尖挑战

目标:具备 IOI 级别建模与创新能力

核心任务:

深入学习:

网络流(最大流、费用流)

数位 DP / 博弈 DP

计算几何(凸包、旋转卡壳)

字符串(KMP、Trie、哈希)

刷 IOI、CEOI、USACO Platinum 历年真题;

参与 Codeforces Div.1 / AtCoder Grand Contest 保持手感;

注重 算法组合创新(如“线段树维护 DP 状态”);

强化 代码规范与可读性,便于快速调试。

铂金真相:题目无标准解法,考的是“现场发明算法”的能力。

USACO竞赛9.9元体验课+集训班

铜级→银级→金级,金牌导师亲授!

扫码了解详细课程安排

USACO 竞赛晋级体系一文说清!为什么顶尖大学如此认可 USACO?

在美本申请日益“内卷”的今天,一个高含金量、可量化、当场出分的学术竞赛,已成为冲刺 MIT、斯坦福、CMU 等顶尖理工院校的“关键筹码”。
而 USACO(美国计算机奥林匹克竞赛),正是这样一项——
✅ 零门槛报名
✅ 当场出成绩、一周内放榜
✅ 级别明确、含金量分层清晰
✅ RD 申请前最后的“闪光点”机会

本文将为你系统拆解:USACO 考什么?怎么晋级?不同级别对申请意味着什么?以及如何科学规划冲奖路径?

一、USACO 基础信息:零门槛,高回报

项目 说明
参赛资格 不限国籍、不限年级、无报名费
报名方式 官网注册即自动进入 青铜级(Bronze)
编程语言 C++、C、Java、Python、Pascal(强烈推荐 C++)
出分速度 当场出成绩,官方榜单通常 1周内公布
适合人群

对计算机、数学、工程方向感兴趣的学生

临近申请季但缺乏强背提活动者(RD 截止前仍可冲刺!)

关键优势:

相比需数月等待结果的竞赛,USACO 是 “最后一刻也能逆袭” 的少数选择。

二、四级晋级体系:层层递进,含金量逐级跃升

USACO 采用阶梯式晋级制,每通过一级,学术价值显著提升:

青铜级(Bronze)—— 入门起点

考察内容:基础语法、模拟、枚举、简单逻辑

能力要求:能读懂题意,写出正确逻辑即可

申请价值:体现兴趣入门,不足以作为核心亮点

白银级(Silver)—— 能力分水岭

核心考点:

贪心策略

二分查找

DFS / BFS 搜索

时间复杂度初步分析

能力跃迁:从“会写代码”到“会设计算法”

申请价值:

Top 30–50 院校:有力加分项

藤校 / Top 10:仅为基础门槛,需继续冲击黄金

黄金级(Gold)—— 名校“硬通货”

核心考点:

动态规划(DP)

最短路(Dijkstra)

并查集、线段树等高级数据结构

对标水平:≈ 国内 NOIP 省一等奖

申请价值:

可作为 Common App “Honors” 栏目重点填写

MIT、Stanford、CMU、UCB、UIUC 等校高度认可

证明具备顶尖计算机专业的学习潜力

铂金级(Platinum)—— 顶峰王者

核心考点:

网络流、计算几何

复杂 DP 优化(斜率优化、状态压缩)

交互式/概率算法

对标水平:≈ IOI 国家队选拔级别

申请价值:

全球每年仅数百人达到

在藤校申请中近乎“决定性优势”

中国学生凤毛麟角,极具稀缺性

三、为什么顶尖大学如此认可 USACO?

招生官看重的,从来不是“你会不会编程”,而是:

1. 真实问题建模能力

USACO 题目常以生活场景为背景:

“奶牛如何排队拍照最省时间?”

“如何调度灌溉系统覆盖所有农田?”
→ 学生需将现实抽象为数学模型,这正是 AI、数据科学的核心思维。

2. 算法思维 vs 死记硬背

题目无模板可套,必须理解原理并灵活组合。
例如:一道题可能融合 贪心 + 二分 + 图论,考验综合应用能力。

3. 可量化的学术成长轨迹

从 Bronze → Platinum 的晋级路径清晰可见,
招生官能直观看到学生的持续投入与能力跃迁。

四、科学备赛规划建议

目标导向型路径

申请目标 建议目标级别 备赛周期
Top 10 / 藤校 Gold 起步,冲刺 Platinum 12–18 个月
Top 30(如 NYU、BU) Silver → Gold 6–12 个月
Top 50(如 UIUC、Purdue) Silver 稳定通过 3–6 个月

语言选择建议

首选 C++:执行效率高、STL 库强大,NOIP 也仅支持 C++,实现“一学两用”;

慎用 Python:虽易上手,但在 Gold+ 级别极易因超时失分。

时间节点提醒

2026 赛季月赛:1月、1月底、2月中(共3场)

RD 申请截止:通常 11 月–1 月
→ 12 月参加月赛,1 月拿 Gold,仍可赶 RD!

USACO竞赛9.9元体验课+集训班

铜级→银级→金级,金牌导师亲授!

扫码了解详细课程安排

2026 年 USACO竞赛 第三场比赛铜奖组问题三—Swap to Win

Farmer John has a favorite string t with M characters. He also has N strings s1,s2,…,sN each with M characters (1≤N,M≤1000).

FJ can perform the following two types of operations:

FJ chooses any string sx
and two indices p
and q
. Then, he swaps the p
'th and q
'th character of sx
(1≤x≤N,1≤p,q≤M
).
FJ chooses two strings sx
and sy
and an index k
. Then, he swaps the k
'th characters of sx
and sy
(1≤x,y≤N,1≤k≤M
).
His goal is to make s1
equal to t
. Find any series of operations that fulfills his goal. Because FJ is in a hurry, he only has time to perform a total of 2M
operations. The inputs guarantee that it is possible to fulfill FJ's goal.

INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains T
(1≤T≤10
), the number of independent tests. Each test is specified in the following format:
The first line contains N
and M
.

The second line contains t
.

Then, N
lines follow, the i
'th of which contains si
.

The inputs will guarantee that it is possible to fulfill FJ's goal. All strings contain lowercase English letters (a-z).

OUTPUT FORMAT (print output to the terminal / stdout):
The output for each test should be as follows:
On the first line, output an integer K
, the number of operations you will perform. K
must be a non-negative integer less than or equal to 2M
.

Then, output K
lines, denoting the operations you will perform in sequential order. Each line should be one of the following:

1 x p q
2 x y k
SAMPLE INPUT:
3
3 6
banana
nabana
banana
nnbaaa
5 3
abc
def
bca
ghi
jkl
mno
3 5
abcde
abcde
abcde
zzzzz
SAMPLE OUTPUT:
3
2 1 2 1
1 1 3 5
2 1 2 5
5
1 2 1 3
2 1 2 1
1 2 2 3
2 1 2 2
2 1 2 3
0
Here is how s
changes according to the first test's output (with letters swapped in uppercase):

nabana Babana baNaBa banaNa
banana -> Nanana -> nanana -> nanaBa
nnbaaa nnbaaa nnbaaa nnbaaa
After all three operations, s1=t
.

SCORING:
Inputs 2-6: N,M≤100
Inputs 7-12: No additional constraints.
Problem credits: Chongtian Ma

2026 年 USACO竞赛 第三场比赛铜奖组问题二—Strange Function

For all positive integers x, the function f(x) is defined as follows:

If x has any digits that aren't 0 or 1, for each digit of x, set it to 1, if it is odd or 0
otherwise, and return x.

Otherwise, return x−1.

Given a value of x (1≤x<), find how many times f needs to be applied to x until x reaches 0. As this number might be very large, output its remainder when divided by 109+7.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains T (1≤T≤105), the number of independent tests.

The next T lines each contain a positive integer x consisting solely of the digits 0-9, with no leading zeros.

It is guaranteed that the total number of digits in all input integers does not exceed 106 .

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, output the remainder of the number of times when divided by 109+7 on a separate line.

SAMPLE INPUT:

2
24680
210

SAMPLE OUTPUT:

1
4

First test: x becomes zero after one operation.

Second test: f(x)=10,f2(x)=9,f3(x)=1,f4(x)=0

SAMPLE INPUT:

1
1234567890123456789012345678901234567890

SAMPLE OUTPUT:

511620083

SCORING:

Inputs 3-5: T≤2000, x<109
Inputs 6-7: x<1018 
Inputs 8-9: x<1060
Inputs 10-12: No additional constraints.

Problem credits: Aidan Bai

2026 年 USACO竞赛 第三场比赛铜奖组问题一—Make All Distinct

You have an integer array a1…aN with elements initially in the range [1,N](1≤N≤2⋅105), as well as a nonzero integer K(−N≤K≤N,K≠0).

You may perform the following operation as many times as you'd like (possibly zero): select an index i and set ai=ai+K.

Find the minimum number of operations to make all array elements distinct.

INPUT FORMAT (input arrives from the terminal / stdin):

The input consists of T (1≤T≤10) independent tests. Each test is described as follows:

The first line contains N and K.

The second line contains a1…aN .

It is guaranteed that the sum of N over all tests does not exceed 106.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test, output a single line containing the minimum number of operations.

Note: The large size of integers involved in this problem may require the use of 64-bit integer data types (e.g., a "long long" in C/C++).

SAMPLE INPUT:

4
4 1
4 1 4 1
4 -3
4 1 4 1
4 4
4 1 4 1
3 -1
1 1 2

SAMPLE OUTPUT:

2
4
2
1

For the first test, here is a possible sequence of two operations that makes all elements distinct.

4 1 4 1
5 1 4 1 (a_1 += 1)
5 1 4 2 (a_4 += 1)

SCORING:

Inputs 2-4: N≤50
Inputs 5-7: N≤2000
Inputs 8-10: K=1
Inputs 11-13: No additional constraints.

Problem credits: Akshaj Arora, Benjamin Qi

2026 年 USACO竞赛 第三场比赛银奖组问题三—Point Elimination

You have N (2≤N≤105,N is even) points (xi,yi)(1≤xi,yi≤106) on an infinite 2D-coordinate plane.

You can perform the following two types of operations any number of times:

Choose two points that are directly adjacent to each other (manhattan distance of 1), and remove both points.

Choose any two points and swap their y-coordinates. Formally, points (a,b) and (c,d) become (a,d) and (c,b) respectively.

Determine if it is possible to eliminate all points on the board. Note that it may be the case that two points may map to the same coordinate; they should still be treated as different points. You also may not directly delete points on the same coordinate, as they are technically not directly adjacent.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains T (1≤T≤5000), the number of test cases.

The first line of each test case contains an integer N.

The following N lines contain two integers xi and yi.

It is guaranteed that the sum of N over all test cases does not exceed 5⋅105.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, output "YES" or "NO" on a new line.

SAMPLE INPUT:

4
2
1 1
1 1
4
6 10
7 11
8 1
8 1
6
1 2
1 3
1 4
1 5
10 10
11 10
6
1 1
1 1
1 1
1 1
10 10
11 11

SAMPLE OUTPUT:

NO
YES
YES
NO

For the first test, the only two points are equal, so no swaps will do anything. Thus, our answer is NO.

In the second test, we can swap the y-coordinates of 6 and 7 with 8 and 8. Then, we can remove the first two points (horizontal adjacency) and the last two (vertical).

For the third test, no swaps are needed. We can remove the first pair, second, and third.

In the last test, it can be shown that no matter how we swap the y-coordinates, we will never be able to remove all the points in adjacent pairs.

SCORING:

Input 2: T≤1000, N≤6
Inputs 3-5: N≤100
Inputs 6-11: No additional constraints.

Problem credits: Alex Pylypenko, Chongtian Ma

2026 年 USACO竞赛 第三场比赛银奖组问题二—Milk Buckets

There are N (1≤N≤2⋅105) buckets in a stack where the i-th bucket from the top has capacity ai gallons (1≤ai≤109). A tap above the top bucket sends one gallon of milk per second into the first bucket per second. There is also a pool below bucket N.

When a bucket reaches its capacity after t seconds, at the start of the t+1 th second it flips to dump its contents into either the bucket below if it is not the last bucket or the pool otherwise (it reverts back to filling at the end of the t+1th second). A bucket cannot collect milk while it is flipped; any milk arriving at the bucket above during this second is lost. Additionally, any amount of milk exceeding the capacity of the bucket below is lost.

Handle Q (1≤Q≤3⋅105) queries, each specified by three integers i, v, and t:

1.First, set ai =v (1≤i≤N,1≤v≤109).
2.Then answer the following question: Suppose that at time 0, all buckets as well as the pool are empty. Determine the number of gallons of milk in the pool after t seconds (1≤t 1018 ).

The ai=v updates persist through later queries.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains N.

The second line contains a1…aN.

The next line contains Q.

Then the following Q lines contain three integers i, v, and t. This means that you should set ai=v and then answer the question for t.

OUTPUT FORMAT (print output to the terminal / stdout):

Output the answer to each question on a separate line.

SAMPLE INPUT:

3
1 1 1
30
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10
1 2 1
1 2 2
1 2 3
1 2 4
1 2 5
1 2 6
1 2 7
1 2 8
1 2 9
1 2 10
2 2 1
2 2 2
2 2 3
2 2 4
2 2 5
2 2 6
2 2 7
2 2 8
2 2 9
2 2 10

SAMPLE OUTPUT:

0
0
0
1
1
2
2
3
3
4
0
0
0
0
1
1
1
2
2
2
0
0
0
0
1
1
1
2
2
2

When a=[1,1,1],

Bucket 1 flips at times 2,4,6,…
Bucket 2 flips at times 3,5,7,…
Bucket 3 flips at times 4,6,8,…

When a=[2,1,1],

Bucket 1 flips at times 3,6,9,…
Bucket 2 flips at times 4,7,10,…
Bucket 3 flips at times 5,8,11,…

When a=[2,2,1],

Bucket 1 flips at times 3,6,9,…
Bucket 2 flips at times 4,7,10,…
Bucket 3 flips at times 5,8,11,…

SAMPLE INPUT:

2
1 2
10
1 1 1
1 1 2
1 1 3
1 1 4
1 1 5
1 1 6
1 1 7
1 1 8
1 1 9
1 1 10

SAMPLE OUTPUT:

0
0
0
0
2
2
2
2
4
4

SAMPLE INPUT:

3
1 1 1
1
1 1 1000000000000000000

SAMPLE OUTPUT:

499999999999999999

SCORING:

Inputs 4-5: N≤10,Q≤100, and all t≤104
Inputs 6-11: N≤103,Q≤104
Inputs 12-23: No additional constraints.

Problem credits: Akshaj Arora

2026 年 USACO竞赛 第三场比赛银奖组问题一—Clash!

Farmer John is playing a famous and strategic card game with his dear cow Bessie. FJ has N (2≤N≤2⋅105) cards, conveniently numbered from 1 to N. The i'th card costs ai (1≤ai ≤109) moolixir if FJ wants to play it.

His hand always consists of H cards at any given time (1≤H<N). Initially, his hand consists of cards 1 through H. The remaining cards are in a draw queue. Every time FJ plays a card in his hand, he will draw its replacement from the front of the draw queue to his hand. Then, FJ will put the card he just played to the back of the draw queue. Initially, cards H+1 through N are arranged from the front to the back of the draw queue in that order.

In this game, time is measured in integer seconds. Initially, the game starts at time 0 with FJ having 0 moolixir. Immediately before each of integer times t=1,2,3,…,moolixir increases by 1. At each integer time, FJ may choose to play a card in his hand if its cost does not exceed FJ's current moolixir count, which subtracts FJ's current moolixir count by the card's cost.

FJ marks a subset of his cards s1,s2,…,sK as win-conditions (1≤kN, 1≤siN). If FJ has at least one win-condition in his hand, the next card he plays must be a win-condition.

He asks you Q (1≤Q≤2⋅105 ) queries. Each query is of the following form: what is the maximum number of win-conditions he could have placed down within t time (1≤t≤1018)?

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains N and H.

The second line contains N integers a1,a2,…,aN .

The third line contains an integer k, the number of win-conditions.

The fourth line contains k distinct integers s1,s2,…,sK.

The fifth line contains an integer Q.

The following Q lines each contain an integer t, the time to answer for each query.

OUTPUT FORMAT (print output to the terminal / stdout):

For each query, output the maximum number of win-conditions that FJ could've put down within t time.

SAMPLE INPUT:

6 3
2 4 3 5 7 6
2
1 4
6
1
2
3
7
10
1000000000000000

SAMPLE OUTPUT:

0
1
1
2
2
142857142857143

In this case, you start with card 1, a win condition on your hand. You can play it after you accumulate 2 elixir in 2 seconds. This means that just after t=1 you can play no cards, but after t=2 you can play your first card, which must be your win condition.

After t=3, it is still most optimal to play card 1 and have 1 elixir remaining, so the answer here is still 1.

You then draw card 4, which is also a win condition. You play it immediately after t=7, so you have played 2 win conditions at this time.

You then draw card 5 and have no win conditions in your hand. After t=10, even if you play card 3 with the 3 elixir you have, your number of win conditions does not change.

SCORING:

Inputs 2-3: N,Q≤100
Inputs 4-5: H=1
Inputs 6-11: No additional constraints.

Problem credits: Chongtian Ma

2026 年 USACO竞赛 第三场比赛金奖组问题三—Random Tree Generation

Suppose the function randint(l,r) returns an integer independently and uniformly at random from the range [l,r].

Bessie generates a random labeled tree on N vertices (2≤N≤2⋅105) using the following two-step process:

1.Start with vertices labeled 1 through N. For each i from 2 to N, add an edge between vertex i and randint(1,i−1).

2.Choose a permutation p1,p2,…,pN of {1,2,…,N} uniformly at random. Relabel every vertex v as pv.

Now, Farmer John is looking at the edge set of the final tree and wants to know the probability that the two-step process above produces a tree with exactly this edge set. Can you determine this probability modulo 109+7?

INPUT FORMAT (input arrives from the terminal / stdin):

The input consists of T(1≤T≤10) independent inputs. Each input is specified as follows:

The first line contains N.

The next N−1 lines contain the edges of the tree specified by two space-separated integers u and v (1≤u,vN). It is guaranteed that these edges induce a tree.

It is guaranteed that the sum of N across all tests does not exceed 5⋅105.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test, output the probability modulo 109+7 on a new line (note that the output probability is a ratio of integers, so you will want to print the result of this division when working modulo 109+7).

SAMPLE INPUT:

4
2
2 1
3
1 2
2 3
4
1 2
2 3
2 4
4
1 2
2 3
3 4

SAMPLE OUTPUT:

1
333333336
83333334
55555556

The probabilities are 1, 1/3, 1/12, 1/18.

First test: There is only one tree on N=2 vertices, so the probability of generating it is just 1.

Second test: there are three trees on N=3 vertices, and each of them is equally likely to have been generated by the process above. And 1/3≡333333336(mod 109+7).

SCORING:

Input 2-3: N≤8
Inputs 4-9: N≤2000
Inputs 10-21: No additional constraints.

Problem credits: Benjamin Qi

2026 年 USACO竞赛 第三场比赛金奖组问题二—Picking Flowers

**Note: The time limit for this problem is 3s, 1.5x the default.**

Farmer John's farm structure can be represented as a connected undirected graph with N vertices and M unweighted edges (2≤N≤2⋅105,N−1≤M≤2⋅105
). Initially, Farmer John is at his barn, represented by farm 1.

Initially, farms s1,s2,…,sK contain flower fields and farms d1,d2,…,dL are destination farms. FJ calls a path pretty if:

It starts at farm 1.
It ends at some destination farm x.
There is no shorter path starting at farm 1and ending at farm x.
FJ visits all flower fields along the way.

FJ can wave his magic wand and make up to one more farm contain a flower field (if it doesn't already). However, FJ isn't very decisive. For farms f numbered 2 through N, after FJ temporarily makes farm f contain a flower field, determine if there exists a pretty path.

Note that there are multiple test cases, and each case must be treated independently.

INPUT FORMAT (input arrives from the terminal / stdin):

The first line contains T (1≤T≤100), the number of independent test cases.

The first line of each test case contains N, M, K, and L(0≤KN−1,1≤LN−1).

The following line contains s1,s2,…,sK ( 2≤ si N, siare all distinct ).

The following line contains d1,d2,…,dL (2≤diN, di are all distinct).

The following M lines contain u and v, denoting there is an undirected edge between farms u and v. All edges are considered to have equal length. It is guaranteed that there aren't any multi-edges or self loops.

It is guaranteed that both the sum of N and the sum of M do not exceed 106 over all test cases.

OUTPUT FORMAT (print output to the terminal / stdout):

For each test case, output a binary string of length N−1. The i'th character in the string should be 1 if the answer holds true for the (i+1)'th farm.

SAMPLE INPUT:

1
7 7 0 1

5
1 2
2 3
3 4
4 5
5 6
6 7
3 6

SAMPLE OUTPUT:

111110

Since 5 is the only destination farm, the answer holds true if the i'th farm lies on any shortest path from 1 to 5.

There are two shortest paths from 1 to 5, which are 1→2→3→4→5 and 1→2→3→6→5.

Since there are no farms that already contain flower fields, the answer for farm i
holds true if farm i lies on at least one of the two aforementioned paths.

SAMPLE INPUT:

1
6 6 0 2

5 3
1 2
2 3
3 4
4 5
5 6
2 5

SAMPLE OUTPUT:

11010

There are two destination farms: 5 and 3. Since there are no farms that already contain flower fields, the i'th farm must lie on a shortest path to either 5 or 3. Since farm 2 lies on a shortest path to farm 5, so the answer holds for farm 2. Trivially, farm 3 lies on the shortest path to farm 3 and farm 5 lies on the shortest path to farm 5.

SAMPLE INPUT:

3
4 3 2 1
2 3
4
1 2
2 3
3 4
4 4 2 1
2 3
4
1 2
1 3
2 4
3 4
5 5 2 1
2 4
5
1 2
1 3
2 4
3 4
4 5

SAMPLE OUTPUT:

111
000
1011

For the first test case, the answer holds true for the i'th farm if FJ can pass through farm i, farm 2, and farm 3 (in no particular order) on some shortest path to farm 4. It can be shown that the answer holds true for all farms.

SCORING:

Inputs 4-6: K=0and L=1
Inputs 7-9: K=0
Inputs 10-23: No additional constraints

Problem credits: Chongtian Ma

在线咨询
微信咨询