提出 #71367489
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
const int N = 300005;
vector<int> adj[N];
int num[N], low[N], ti;
bool h2[N], bad;
int bl[N], ye[N];
bool vis[N];
int p[N];
int par_ear[N];
void dfs(int u, int pa) {
num[u] = low[u] = ++ti;
if(u == 2) h2[u] = 1;
for(int v : adj[u]) {
if(v == pa) continue;
if(num[v]) low[u] = min(low[u], num[v]);
else {
dfs(v, u);
low[u] = min(low[u], low[v]);
if(h2[v]) h2[u] = 1;
if(low[v] > num[u] && !h2[v]) bad = 1;
}
}
}
void get_bb(int s, int t) {
queue<int> q;
q.push(s);
p[s] = -1;
while(q.size()) {
int u = q.front(); q.pop();
if(u == t) break;
for(int v : adj[u]) {
if(!p[v]) {
p[v] = u;
q.push(v);
}
}
}
}
void get_ear(int s, int fu, vector<int>& qm) {
queue<int> q;
q.push(s);
vector<int> touched;
par_ear[s] = fu;
touched.push_back(s);
int tw = -1;
while(q.size()) {
int u = q.front(); q.pop();
bool found = false;
for(int v : adj[u]) {
if(v == fu && u == s) continue;
if(vis[v]) {
tw = v;
par_ear[v] = u;
touched.push_back(v);
found = true;
break;
}
if(par_ear[v] == 0) {
par_ear[v] = u;
touched.push_back(v);
q.push(v);
}
}
if(found) break;
}
int u = tw;
int pre = -1;
while(u != s) {
int pa = par_ear[u];
if(!vis[u]) {
bl[u] = pa;
if(pre == -1) ye[u] = tw;
else ye[u] = pre;
vis[u] = 1;
qm.push_back(u);
}
pre = u;
u = pa;
}
bl[s] = fu;
ye[s] = pre;
vis[s] = 1;
qm.push_back(s);
for(int x : touched) par_ear[x] = 0;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m;
if(!(cin >> n >> m)) return 0;
for(int i = 0; i < m; i++){
int u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
if(bad) {
cout << "No\n";
return 0;
}
cout << "Yes\n";
get_bb(1, 2);
vector<int> backbone;
int curr = 2;
while(curr != -1) {
backbone.push_back(curr);
curr = p[curr];
}
reverse(backbone.begin(), backbone.end());
vector<int> qm;
for(int i = 0; i < backbone.size(); i++){
int u = backbone[i];
vis[u] = 1;
qm.push_back(u);
if(i > 0) bl[u] = backbone[i-1];
if(i < backbone.size() - 1) ye[u] = backbone[i+1];
}
int head = 0;
while(head < qm.size()){
int u = qm[head++];
for(int v : adj[u]){
if(!vis[v]) {
get_ear(v, u, qm);
}
}
}
cout << ye[1] << "\n";
cout << bl[2] << "\n";
for(int i = 3; i <= n; i++){
cout << bl[i] << " " << ye[i] << "\n";
}
return 0;
}
提出情報
| 提出日時 | |
|---|---|
| 問題 | D - Michishirube |
| ユーザ | Luongdung |
| 言語 | C++23 (GCC 15.2.0) |
| 得点 | 700 |
| コード長 | 3273 Byte |
| 結果 | AC |
| 実行時間 | 125 ms |
| メモリ | 33496 KiB |
コンパイルエラー
./Main.cpp: In function 'int main()':
./Main.cpp:122:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
122 | for(int i = 0; i < backbone.size(); i++){
| ~~^~~~~~~~~~~~~~~~~
./Main.cpp:127:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
127 | if(i < backbone.size() - 1) ye[u] = backbone[i+1];
| ~~^~~~~~~~~~~~~~~~~~~~~
./Main.cpp:131:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | while(head < qm.size()){
| ~~~~~^~~~~~~~~~~
ジャッジ結果
| セット名 | Sample | All | ||||
|---|---|---|---|---|---|---|
| 得点 / 配点 | 0 / 0 | 700 / 700 | ||||
| 結果 |
|
|
| セット名 | テストケース |
|---|---|
| Sample | 00-sample-001.txt, 00-sample-002.txt |
| All | 00-sample-001.txt, 00-sample-002.txt, 01-non_bridge_yes-001.txt, 01-non_bridge_yes-002.txt, 01-non_bridge_yes-003.txt, 01-non_bridge_yes-004.txt, 01-non_bridge_yes-005.txt, 02-less_bridge_yes-001.txt, 02-less_bridge_yes-002.txt, 02-less_bridge_yes-003.txt, 02-less_bridge_yes-004.txt, 02-less_bridge_yes-005.txt, 02-less_bridge_yes-006.txt, 02-less_bridge_yes-007.txt, 02-less_bridge_yes-008.txt, 02-less_bridge_yes-009.txt, 02-less_bridge_yes-010.txt, 03-many_bridge_yes-001.txt, 03-many_bridge_yes-002.txt, 03-many_bridge_yes-003.txt, 03-many_bridge_yes-004.txt, 03-many_bridge_yes-005.txt, 03-many_bridge_yes-006.txt, 03-many_bridge_yes-007.txt, 03-many_bridge_yes-008.txt, 03-many_bridge_yes-009.txt, 03-many_bridge_yes-010.txt, 04-small_yes-001.txt, 04-small_yes-002.txt, 04-small_yes-003.txt, 04-small_yes-004.txt, 04-small_yes-005.txt, 05-no-001.txt, 05-no-002.txt, 05-no-003.txt, 05-no-004.txt, 05-no-005.txt, 05-no-006.txt, 05-no-007.txt, 05-no-008.txt, 05-no-009.txt, 05-no-010.txt |
| ケース名 | 結果 | 実行時間 | メモリ |
|---|---|---|---|
| 00-sample-001.txt | AC | 2 ms | 3736 KiB |
| 00-sample-002.txt | AC | 2 ms | 3752 KiB |
| 01-non_bridge_yes-001.txt | AC | 114 ms | 33496 KiB |
| 01-non_bridge_yes-002.txt | AC | 111 ms | 20428 KiB |
| 01-non_bridge_yes-003.txt | AC | 102 ms | 22936 KiB |
| 01-non_bridge_yes-004.txt | AC | 117 ms | 19248 KiB |
| 01-non_bridge_yes-005.txt | AC | 99 ms | 21332 KiB |
| 02-less_bridge_yes-001.txt | AC | 117 ms | 22652 KiB |
| 02-less_bridge_yes-002.txt | AC | 109 ms | 21368 KiB |
| 02-less_bridge_yes-003.txt | AC | 116 ms | 22172 KiB |
| 02-less_bridge_yes-004.txt | AC | 113 ms | 20676 KiB |
| 02-less_bridge_yes-005.txt | AC | 107 ms | 20928 KiB |
| 02-less_bridge_yes-006.txt | AC | 117 ms | 22196 KiB |
| 02-less_bridge_yes-007.txt | AC | 119 ms | 23360 KiB |
| 02-less_bridge_yes-008.txt | AC | 113 ms | 22348 KiB |
| 02-less_bridge_yes-009.txt | AC | 119 ms | 22924 KiB |
| 02-less_bridge_yes-010.txt | AC | 111 ms | 21248 KiB |
| 03-many_bridge_yes-001.txt | AC | 107 ms | 32212 KiB |
| 03-many_bridge_yes-002.txt | AC | 110 ms | 32780 KiB |
| 03-many_bridge_yes-003.txt | AC | 117 ms | 26172 KiB |
| 03-many_bridge_yes-004.txt | AC | 122 ms | 27228 KiB |
| 03-many_bridge_yes-005.txt | AC | 115 ms | 30828 KiB |
| 03-many_bridge_yes-006.txt | AC | 125 ms | 27876 KiB |
| 03-many_bridge_yes-007.txt | AC | 110 ms | 32684 KiB |
| 03-many_bridge_yes-008.txt | AC | 124 ms | 27028 KiB |
| 03-many_bridge_yes-009.txt | AC | 109 ms | 30256 KiB |
| 03-many_bridge_yes-010.txt | AC | 108 ms | 32396 KiB |
| 04-small_yes-001.txt | AC | 3 ms | 3700 KiB |
| 04-small_yes-002.txt | AC | 2 ms | 3536 KiB |
| 04-small_yes-003.txt | AC | 2 ms | 3732 KiB |
| 04-small_yes-004.txt | AC | 2 ms | 3700 KiB |
| 04-small_yes-005.txt | AC | 2 ms | 3676 KiB |
| 05-no-001.txt | AC | 63 ms | 26372 KiB |
| 05-no-002.txt | AC | 64 ms | 21736 KiB |
| 05-no-003.txt | AC | 63 ms | 26128 KiB |
| 05-no-004.txt | AC | 57 ms | 23808 KiB |
| 05-no-005.txt | AC | 63 ms | 18768 KiB |
| 05-no-006.txt | AC | 70 ms | 22928 KiB |
| 05-no-007.txt | AC | 63 ms | 24176 KiB |
| 05-no-008.txt | AC | 63 ms | 26664 KiB |
| 05-no-009.txt | AC | 66 ms | 21184 KiB |
| 05-no-010.txt | AC | 59 ms | 22348 KiB |