結果
| 問題 |
No.1553 Lovely City
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-05-05 22:52:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,504 bytes |
| コンパイル時間 | 4,440 ms |
| コンパイル使用メモリ | 261,608 KB |
| 最終ジャッジ日時 | 2025-01-21 07:39:24 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 10 WA * 16 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:57:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
57 | scanf("%d %d",&a[i],&b[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint1000000007;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000
vector<int> A,B;
void go(vector<int> ind,vector<int> a,vector<int> b){
int n = ind.size();
sort(ind.begin(),ind.end());
scc_graph S(n);
rep(i,a.size()){
int x = distance(ind.begin(),lower_bound(ind.begin(),ind.end(),a[i]));
int y = distance(ind.begin(),lower_bound(ind.begin(),ind.end(),b[i]));
S.add_edge(x,y);
}
vector<vector<int>> s = S.scc();
rep(i,s.size()){
if(i+1!=s.size()){
A.push_back(ind[s[i][0]]);
B.push_back(ind[s[i+1][0]]);
}
if(s[i].size()>=2){
rep(j,s[i].size()){
int x = s[i][j];
int y = s[i][(j+1)%s[i].size()];
A.push_back(ind[x]);
B.push_back(ind[y]);
}
}
}
}
int main(){
int N,M;
cin>>N>>M;
vector<int> a(M),b(M);
dsu D(N);
rep(i,M){
scanf("%d %d",&a[i],&b[i]);
a[i]--;b[i]--;
D.merge(a[i],b[i]);
}
vector<int> pos(N);
vector<vector<int>> ret = D.groups();
rep(i,ret.size()){
rep(j,ret[i].size()){
pos[ret[i][j]] = i;
}
}
// cout<<'a'<<endl;
vector<vector<int>> aa(ret.size()),bb(ret.size());
rep(i,M){
int ind = pos[a[i]];
aa[ind].push_back(a[i]);
bb[ind].push_back(b[i]);
}
rep(i,ret.size()){
go(ret[i],aa[i],bb[i]);
}
//cout<<'a'<<endl;
cout<<A.size()<<endl;
rep(i,A.size()){
printf("%d %d\n",A[i]+1,B[i]+1);
}
return 0;
}
沙耶花