結果

問題 No.1983 [Cherry 4th Tune C] 南の島のマーメイド
ユーザー woodywoodywoodywoody
提出日時 2022-06-18 20:26:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 6,329 bytes
コンパイル時間 5,798 ms
コンパイル使用メモリ 254,860 KB
実行使用メモリ 109,608 KB
最終ジャッジ日時 2024-04-18 18:05:22
合計ジャッジ時間 48,589 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,752 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 19 ms
5,376 KB
testcase_09 AC 28 ms
5,376 KB
testcase_10 AC 59 ms
8,704 KB
testcase_11 AC 57 ms
8,320 KB
testcase_12 AC 24 ms
5,376 KB
testcase_13 AC 2,075 ms
51,868 KB
testcase_14 AC 2,734 ms
67,148 KB
testcase_15 AC 1,829 ms
52,176 KB
testcase_16 AC 381 ms
32,896 KB
testcase_17 AC 1,743 ms
71,344 KB
testcase_18 AC 1,216 ms
47,276 KB
testcase_19 AC 2,632 ms
96,560 KB
testcase_20 AC 1,082 ms
49,764 KB
testcase_21 TLE -
testcase_22 AC 2,236 ms
89,960 KB
testcase_23 AC 2,464 ms
109,608 KB
testcase_24 AC 2,398 ms
109,232 KB
testcase_25 AC 2,422 ms
109,484 KB
testcase_26 AC 2,923 ms
109,472 KB
testcase_27 TLE -
testcase_28 TLE -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
#define rep(i,b) for(int i=0;i<b;i++)
#define rrep(i,b) for(int i=b-1;i>=0;i--)
#define rep1(i,b) for(int i=1;i<b;i++)
#define repx(i,x,b) for(int i=x;i<b;i++)
#define fore(i,a) for(auto i:a)
#define fore1(i,a) for(auto &i:a)
#define rng(x) (x).begin(), (x).end()
#define rrng(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define fi first
#define se second

using namespace std;
using namespace atcoder;

using ll = long long;
template<typename T> using mpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<typename T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T> ll sumv(const vector<T>&a){ll res(0);for(auto&&x:a)res+=x;return res;}
bool yn(bool a) { if(a) {cout << "Yes" << endl; return 1;} else {cout << "No" << endl; return 0;}}
#define dame { cout << "No" << endl; return 0;}
#define dame1 { cout << -1 << endl; return 0;}
#define test(x) cout << "test" << x << endl;
#define deb(x,y) cout << x << " " << y << endl;
#define deb3(x,y,z) cout << x << " " << y << " " << z << endl;
#define deb4(x,y,z,x2) cout << x << " " << y << " " << z << " " << x2 << endl;
#define out cout << ans << endl;
#define outv fore(yans , ans) cout << yans << "\n";
#define show(x) cerr<<#x<<" = "<<x<<endl;
#define showv(v) {fore(vy , v) {cout << vy << " ";} cout << endl;}
#define showv2(v) fore(vy , v) cout << vy << "\n";
using pll = pair<ll,ll>;
using pil = pair<int,ll>;
using pli = pair<ll,int>;
using pii = pair<int,int>;
using tp = tuple<int ,int ,int>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using vpii = vector<pii>;
using vpli = vector<pli>;
using vpll = vector<pll>;
using vpil = vector<pil>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvs = vector<vector<string>>;
using vvb = vector<vector<bool>>;
using vvpii = vector<vector<pii>>;
using vvpli = vector<vector<pli>>;
using vvpll = vector<vpll>;
using vvpil = vector<vpil>;
using mint = modint998244353;
using vm = vector<mint>;
using vvm = vector<vector<mint>>;
vector<int> dx={1,0,-1,0,1,1,-1,-1},dy={0,1,0,-1,1,-1,1,-1};
ll gcd(ll a, ll b) { return a?gcd(b%a,a):b;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

template<typename T>
struct lca {
  int n, root, l;
  vector<vector<int>> to;
  vector<vector<T>> co;
  vector<int> dep;
  vector<T> costs;
  vector<vector<int>> par;
  lca(int n):n(n),to(n),co(n),dep(n),costs(n) {
    l = 0;
    while ((1<<l) < n) ++l;
    par = vector<vector<int>>(n+1,vector<int>(l,n));
  }
  void add_edge(int a, int b, T c=0) {
    to[a].push_back(b); co[a].push_back(c);
    to[b].push_back(a); co[b].push_back(c);
  }
  void dfs(int v, int d=0, T c=0, int p=-1) {
    if (p != -1) par[v][0] = p;
    dep[v] = d;
    costs[v] = c;
    for (int i = 0; i < to[v].size(); ++i) {
      int u = to[v][i];
      if (u == p) continue;
      dfs(u, d+1, c+co[v][i], v);
    }
  }

  void init(int _root=0) {
    root = _root;
    dfs(root);
    for (int i = 0; i < l-1; ++i) {
      for (int v = 0; v < n; ++v) {
        par[v][i+1] = par[par[v][i]][i];
      }
    }
  }
  // LCA
  int operator()(int a, int b) {
    if (dep[a] > dep[b]) swap(a,b);
    int gap = dep[b]-dep[a];
    for (int i = l-1; i >= 0; --i) {
      int len = 1<<i;
      if (gap >= len) {
        gap -= len;
        b = par[b][i];
      }
    }
    if (a == b) return a;
    for (int i = l-1; i >= 0; --i) {
      int na = par[a][i];
      int nb = par[b][i];
      if (na != nb) a = na, b = nb;
    }
    return par[a][0];
  }
  int length(int a, int b) {
    int c = lca(a,b);
    return dep[a]+dep[b]-dep[c]*2;
  }
  T dist(int a, int b) {
    int c = lca(a,b);
    return costs[a]+costs[b]-costs[c]*2;
  }
};

// 初期化方法 lca<T> g(n) :: nは頂点数、T1はコストのタイプ
// g.add_edge(a,b,c) :: a,b間にコストcの辺をはる。cは省略可(0となる)。
// g.dfs(v) :: vからdfs。各頂点の深さと根からの到達コストを計算。
// g.init() :: ダブリングにより各頂点の2^i個上の親を計算。結果はpar[v][i]に入る。
// g(a,b) :: 頂点a,bのlcaを出力。
// g.length(a,b) :: 頂点a,b間の辺の数を出力。
// g.dist(a,b) :: 頂点a,b間のコストを出力。

vvi e;
int n;

vl va;
map<pii , int> mp;

unordered_map<int , int> mpnr;
unordered_map<int , int> mpn;

vb flg;

int dfs(int x,int pre){

    int ret = va[x];

    fore(ytmp , e[mpnr[x]]){
        int y = mpn[ytmp];
        if(y == pre) continue;

        ret += dfs(y ,x);
    }

    if (ret != 0 && pre != -1) flg[mp[{mpnr[x] , mpnr[pre]}]] = true;

    return ret;
}

int main(){
    int m,q; cin>>n>>m>>q;

    vvi res(n);
    vvi to(n);
    dsu d(n);

    e.resize(n);
    va.resize(n);
    flg.resize(m);


    rep(i,m){
        int a,b; cin>>a>>b; a--; b--;

        mp[{a,b}] = i;
        mp[{b,a}] = i;

        if (d.same(a,b)) res[a].pb(b);
        else{
            d.merge(a,b);
            to[a].pb(b);
            e[a].pb(b);
            e[b].pb(a);
        }
    }

    
    vvi v = d.groups();

    fore(y , v){
        if (sz(mpnr)) assert(0);
        int ts = sz(y);
        lca<int> tr(ts);

        int k = 0;

        fore(yy , y){
            mpn[yy] = k;
            mpnr[k++] = yy;
        }

        fore(yy , y){
            fore(ey , to[yy]) tr.add_edge(mpn[ey] , mpn[yy]);
        }

        tr.init();

        fore(yy , y){
            fore(ey , res[yy]){
                int a = mpn[yy];
                int b = mpn[ey];
                int c = tr(a , b);

                va[a] += 1;
                va[b] += 1;
                va[c] -= 2;

                flg[mp[{yy , ey}]] = true;
            }
        }

        dfs(y[0] , -1);

        mpnr.clear();
        mpn.clear();
        rep(i,k) va[i] = 0;
    }

    dsu d2(n);

    rep(i,n){
        fore(y , to[i]){
            int j = mp[{y , i}];

            if (!flg[j]) d2.merge(y , i);
        }
    }

    vb ans(q);

    rep(i,q){
        int a,b; cin>>a>>b; a--; b--;
        ans[i] = d2.same(a,b);
    }

    fore(y , ans) yn(y);

    return 0;
}
0