QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#424545#6679. Not Another Path Query Problem666ldcTL 1ms3836kbC++201.8kb2024-05-29 12:31:562024-05-29 12:31:57

Judging History

This is the latest submission verdict.

  • [2024-05-29 12:31:57]
  • Judged
  • Verdict: TL
  • Time: 1ms
  • Memory: 3836kb
  • [2024-05-29 12:31:56]
  • Submitted

answer

#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define endl '\n'
#define int long long
typedef long double f128;
typedef long long i64;
typedef unsigned long long u64;
typedef pair<int, int> PII;
const int INF = 0x3f3f3f3f, mod = 1e9 + 7;
const i64 inf = 2e18;
//-------------------------------------------
const int N = 1e5+10,M = 5e5+10;
vector<PII> h[N];
array<int, 2> Q[M];
int lowbit(int x)
{
  return x & (-x);
}
void solve()
{
  int n, m, q, V;
  cin >> n >> m >> q >> V;
  for (int i = 1; i <= m; i++)
  {
    int x, y, w;
    cin >> x >> y >> w;
    h[x].push_back({y, w});
    h[y].push_back({x, w});
  }
  for (int i = 1; i <= q; i++)
    cin >> Q[i][0] >> Q[i][1];
  vector<bool> ans(q + 1);
  auto check = [&](int x)
  {
    vector<int> col(n + 1);
    auto bfs = [&](int z)
    {
      queue<int> q;
      q.push(z);
      col[z] = z;
      while (!q.empty())
      {
        auto t = q.front();
        q.pop();
        for (auto a : h[t])
        {
          if ((a.y & x) == x && !col[a.x])
          {
            col[a.x] = z;
            q.push(a.x);
          }
        }
      }
    };
    for (int i = 1; i <= n; i++)
    {
      if (!col[i])
        bfs(i);
    }
    for (int i = 1; i <= q; i++)
    {
      if (col[Q[i][0]] == col[Q[i][1]])
        ans[i] = true;
    }
  };

  for (int i = V; i < (1LL << 60); i += lowbit(i))
    check(i);
  for (int i = 1; i <= q; i++)
  {
    if (ans[i])
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int T = 1;
  // cin >> T;
  for (int i = 1; i <= T; i++)
    solve();
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3836kb

input:

9 8 4 5
1 2 8
1 3 7
2 4 1
3 4 14
2 5 9
4 5 7
5 6 6
3 7 15
1 6
2 7
7 6
1 8

output:

Yes
No
Yes
No

result:

ok 4 token(s): yes count is 2, no count is 2

Test #2:

score: 0
Accepted
time: 1ms
memory: 3540kb

input:

3 4 1 4
1 2 3
1 2 5
2 3 2
2 3 6
1 3

output:

Yes

result:

ok YES

Test #3:

score: -100
Time Limit Exceeded

input:

100 2000 50000 0
32 52 69658009083393280
26 38 868250171554967916
87 32 743903879320440454
22 15 19782587273744714
57 98 845866434191429143
42 95 1145336983294966993
67 40 1036117659380117375
46 24 265457274847122243
63 44 438254608190938148
28 23 992625102587165494
57 87 558124114385470345
6 17 535...

output:


result: