QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#465368#6872. Magma CaveFortitudeTL 0ms0kbC++231.9kb2024-07-06 20:23:332024-07-06 20:23:35

Judging History

你现在查看的是最新测评结果

  • [2024-07-06 20:23:35]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-07-06 20:23:33]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define f first
#define s second
using namespace std;
using ll = long long;
using pii = pair <int, int>;
const int N = 2e5 + 5;
int n, q, p[N];
int get(int v) {
    if (p[v] == v)
        return v;
    return p[v] = get(p[v]);
}
bool uni(int u, int v) {
    u = get(u), v = get(v);
    if (u == v)
        return 0;
    p[u] = v;
    return 1;
}
void solve() {
    cin >> n >> q;
    vector <pair <int, pii> > ed;
    vector <int> weights;
    for (int i = 1; i <= q; ++i)
        weights.pb(i);
    for (int _ = 0; _ < q; ++_) {
        int tp;
        cin >> tp;
        if (tp == 1) {
            int u, v, w;
            cin >> u >> v >> w;
            ed.pb({w, {u, v}});
            sort(all(ed));
        } else {
            int k, w;
            cin >> k >> w;
            
            bool fnd = 0;
            for (int mask = 0; mask < (1 << sz(ed)); ++mask) {
                if (__builtin_popcount(mask) != n - 1)
                    continue;
                vector <int> vec;
                bool ok = 1;
                for (int i = 1; i <= n; ++i)
                    p[i] = i;
                for (int i = 0; i < sz(ed); ++i) {
                    if ((mask >> i) & 1) {
                        vec.pb(ed[i].f);
                        if (!uni(ed[i].s.f, ed[i].s.s))
                            ok = 0;
                    }
                }
                sort(all(vec));
                ok &= (vec[k - 1] == w);
                if (ok) {
                    fnd = 1;
                    break;
                }
            }
            
            cout << (fnd ? "YES\n" : "NO\n");
        }
    }
}
int main() {
    ios :: sync_with_stdio(false);
    cin.tie(nullptr);
    srand(time(0));
    int TT;
    cin >> TT;
    while (TT--)
        solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

100
500 1999
1 112 419 318
1 419 208 1700
1 208 255 603
1 255 202 306
1 202 54 326
1 54 468 1506
1 468 23 856
1 23 90 758
1 90 271 1104
1 271 442 1900
1 442 441 19
1 441 378 1227
1 378 466 24
1 466 186 228
1 186 399 1387
1 399 288 297
1 288 144 1763
1 144 418 1896
1 418 217 673
1 217 281 1259
1 281 ...

output:


result: