結果
| 問題 |
No.1983 [Cherry 4th Tune C] 南の島のマーメイド
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-09-23 17:19:09 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 213 ms / 4,000 ms |
| コード長 | 1,575 bytes |
| コンパイル時間 | 13,047 ms |
| コンパイル使用メモリ | 278,404 KB |
| 実行使用メモリ | 53,580 KB |
| 最終ジャッジ日時 | 2024-09-23 17:23:48 |
| 合計ジャッジ時間 | 26,811 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 41 |
ソースコード
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#include <sys/ucontext.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ll = long long;
using vi = vector<int>;
using ar2 = array<int,2>;
using ar4 = array<int,4>;
const int mxN = (int)2e5+2;
const int INF = (int)1e9;
const ll LINF = (ll)2e18;
const int MOD = (1ll<<61)-1;
int n, m, q, dfs_tim;
int st[mxN], low[mxN], vis[mxN];
vi adj[mxN];
struct DSU{
int p[mxN], sz[mxN];
void init(int n){
for(int i = 1; i <= n; i++)
p[i]=i, sz[i]=1;
}
int findSet(int i){ return i==p[i]?i:p[i]=findSet(p[i]); }
bool isSameSet(int i, int j){return findSet(i)==findSet(j); }
void unionSet(int i, int j){
int x = findSet(i), y = findSet(j);
if(x==y) return;
if(sz[x]<sz[y])swap(x,y);
p[y]=x, sz[x]+=sz[y];
}
} dsu;
void dfs(int s, int p){
st[s] = low[s] = dfs_tim++; vis[s] = 1;
for(auto u : adj[s]){
if(u==p) continue;
if(!vis[u]){
dfs(u,s); low[s]=min(low[s],low[u]);
if(low[u]>st[s]) dsu.unionSet(s,u);
}
else low[s]=min(low[s],st[u]);
}
vis[s] = 2;
}
void solve(){
cin >> n >> m >> q; dsu.init(n);
for(int i = 1; i <= m; i++){
int a, b; cin >> a >> b;
adj[a].pb(b); adj[b].pb(a);
}
for(int i = 1; i <= n; i++) if(!vis[i]) dfs(i,-1);
for(int i = 1; i <= q; i++){
int x, y; cin >> x >> y;
cout << (dsu.isSameSet(x,y)?"Yes":"No") << "\n";
}
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1; //cin >> t;
while(t--) solve();
}