RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0646

Reachable Pairs

Platinum II 플래티넘 II
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

Consider an undirected graph with \(N\) nodes labeled \(1\dots N\) and \(M\) edges
(\(1\le N\le 2\cdot 10^5, 0\le M\le 4\cdot 10^5\)). You're given a binary string
\(s_1s_2\dots s_N\). At time \(t\) for each \(t\in [1,N]\),

  • If \(s_t=0\), node \(t\) is removed from the graph.
  • If \(s_t=1\), node \(t\) is removed from the graph, and edges are added between every pair of neighbors that node \(t\) had just before removal.

Note that in both cases, when a node is removed from the graph all of its
incident edges are removed as well.

Count the number of pairs of nodes that can reach each other via some sequence
of edges just before each of timesteps \(1\ldots N\).

Problem credits: Benjamin Qi

제약

SCORING

  • Inputs 4-6: \(N\le 100\)
  • Inputs 7-8: All \(s_i\) equal zero.
  • Inputs 9-11: All \(s_i\) equal one.
  • Inputs 12-23: No additional constraints.

Problem credits: Benjamin Qi

입력 형식

The first line contains \(N\) and \(M\).

The second line contains the bit string \(s\) of length \(N\).

The next \(M\) lines each contain two integers denoting an edge of the graph.

출력 형식

\(N\) lines, the number of pairs before each timestep.

예제 1
입력
3 2
111
1 2
1 3
출력
3
1
0
설명

Before any removals, all pairs of nodes are reachable from each other. After
node \(1\) is removed, an edge is added between \(2\) and \(3\), so they can still
reach each other.

예제 2
입력
3 2
000
1 2
1 3
출력
3
0
0
설명

Before any removals, all pairs of nodes are reachable from each other. After
node \(1\) is removed, \(2\) and \(3\) can no longer reach each other.

예제 3
입력
7 8
1101101
6 2
1 2
2 3
6 3
1 3
1 7
4 5
2 7
출력
11
7
4
2
1
1
0
문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2024-2025 > January > Gold

태그

평가 및 의견

Reachable Pairs

개요
출제자 난이도 Platinum II 플래티넘 II 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Reachable Pairs

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8