QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#573386#3940. ISP MergerLaVuna47#WA 1ms3860kbC++174.1kb2024-09-18 18:30:362024-09-18 18:30:37

Judging History

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

  • [2024-09-18 18:30:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3860kb
  • [2024-09-18 18:30:36]
  • 提交

answer

/** gnu specific **/
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
/** contains everything I need in std **/
#include <bits/stdc++.h>

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(S) ((int)S.size())
#define FOR(i, n) for(int i = 0; i < n; ++i)
#define RFOR(i, n) for(int i = n-1; i >= 0; --i)
#define output_vec(vec) { FOR(i_, sz(vec)) cout << vec[i_] << ' '; cout << '\n'; }
#define x first
#define y second
#define pb push_back
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<bool> vb;
typedef short si;
typedef unsigned long long ull;
typedef long double LD;
typedef pair<ull, ull> pull;
using namespace __gnu_pbds;
typedef tree<ll, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
using namespace std;
#ifdef ONPC
mt19937 rnd(228);
#else
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

vector<vector<int>> g;
vector<bool> vis;

void dfs(int v, vector<int>& comp)
{
    vis[v] = 1;
    comp.pb(v);
    for (int to: g[v])
        if (!vis[to])
            dfs(to, comp);
}

int solve()
{
    int n, m, k;
    if (!(cin >> n >> m >> k))
        return 1;
        
    g.clear();
    g.resize(n);
    vis.clear();
    vis.resize(n, false);
    vector<int> cap(n);
    FOR (i, n)
        cin >> cap[i];
        
    FOR (i, m)
    {
        int v, w;
        cin >> v >> w;
        g[v].pb(w);
        g[w].pb(v);
    }
        
    if (n == 1)
    {
        cout << "yes\n";
        return 0;
    }
        
    vector<vector<int>> comps;
    vector<int> comp;
    FOR (i, n)
    {
        if (!vis[i])
            dfs(i, comp);
        if (!comp.empty())
            comps.pb(comp);
        comp.clear();
    }
    
    int nn = sz(comps);
    //cout << "nn = " << nn << '\n';
    if (nn == 1)
    {
        cout << "yes\n";
        return 0;
    }
    // 1 < nn -k
    if (nn - k > 1)
    {
        cout << "no\n";
        return 0;
    }
        
    vector<int> caps(nn), as(nn);
    FOR (i, nn)
    {
        int curr = 0;
        auto el = comps[i];
        for (int idx: el)
            curr += -sz(g[idx]) + cap[idx];
        caps[i] = curr;
        curr = 0;
        for (int idx: el)
            curr += sz(g[idx]);
        curr /= 2;
        //cout << "curr = " << curr << '\n';
        as[i] = curr - (sz(comps[i]) - 1);
    }
     
    //FOR (i, nn)
        //cout << as[i] << ' ';
    //cout << '\n';
     
    vector<int> newcaps, newas;
    FOR (i, nn)
    {
        if (caps[i])
        {
            newcaps.pb(caps[i]);
            newas.pb(as[i]);
        }
        else if (as[i])
        {
            newcaps.pb(caps[i] + 2);
            newas.pb(as[i] - 1);
        }
        else
        {
            newcaps.pb(1);
            newcaps.pb(1);
            newas.pb(0);
            newas.pb(0);
        }
    }
        
    caps.swap(newcaps);
    as.swap(newas);
    nn = sz(caps);
    int sma = accumulate(all(as), 0);
    int smcaps = accumulate(all(caps), 0);
    k -= nn - 1;
    if (k < 0)
    {
        cout << "no\n";
        return 0;
    }
        
    while (sma > 0 && smcaps < 2 * (nn - 1))
    {
        sma--;
        smcaps += 2;
        --k;
        if (k < 0)
        {
            cout << "no\n";
            return 0;
        }
    }
     
    if (smcaps >= 2 * (nn - 1))
        cout << "yes\n";
    else
        cout << "no\n";
        
    return 0;
}

int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int TET = 1e9;
    //cin >> TET;
    for (int i = 1; i <= TET; i++)
    {
        if (solve())
        {
            break;
        }
#ifdef ONPC
        cout << "__________________________" << endl;
#endif
    }
#ifdef ONPC
    cerr << endl << "finished in " << clock() * 1.0 / CLOCKS_PER_SEC << " sec" << endl;
#endif
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3656kb

input:

4 5 2
3 3 3 3
0 1
0 3
1 3
1 2
2 3

output:

yes

result:

ok answer is YES

Test #2:

score: 0
Accepted
time: 0ms
memory: 3712kb

input:

5 4 4
1 1 2 2 2
0 1
2 3
3 4
4 2

output:

yes

result:

ok answer is YES

Test #3:

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

input:

3 0 3
1 1 1

output:

no

result:

ok answer is NO

Test #4:

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

input:

500 500 165
2 2 2 1 2 3 3 2 2 3 3 3 3 2 3 4 2 1 1 2 5 1 1 1 3 1 1 1 1 1 1 1 2 1 1 1 4 2 2 3 1 3 2 2 1 2 4 1 1 1 1 5 2 2 1 4 1 2 5 1 3 2 1 2 5 1 2 1 2 3 2 1 2 1 1 2 1 1 1 1 2 4 2 1 3 3 4 3 3 1 3 2 1 1 1 2 2 2 1 1 1 2 5 1 3 5 3 2 2 2 2 2 4 1 2 3 2 2 2 2 2 1 2 2 3 2 2 2 4 4 5 1 4 1 1 1 4 4 1 2 1 2 2 2 ...

output:

yes

result:

ok answer is YES

Test #5:

score: 0
Accepted
time: 0ms
memory: 3772kb

input:

504 502 159
2 1 3 1 3 2 1 1 2 3 3 1 7 1 3 2 2 2 4 1 2 1 2 3 1 1 1 3 1 2 3 2 1 1 2 1 1 4 1 4 1 3 1 2 3 2 2 2 3 3 1 3 2 4 2 1 1 2 1 2 1 1 3 1 1 5 1 2 2 4 1 3 3 2 1 1 1 3 1 2 3 2 3 1 1 3 3 1 5 1 5 1 2 2 2 1 2 2 2 1 1 1 1 1 3 1 2 3 3 1 3 1 1 1 1 2 3 1 6 3 2 2 1 1 1 1 3 3 4 3 3 2 4 1 1 1 2 4 1 3 2 1 3 1 ...

output:

yes

result:

ok answer is YES

Test #6:

score: -100
Wrong Answer
time: 1ms
memory: 3860kb

input:

504 503 154
1 1 2 3 1 1 2 1 1 1 4 2 1 2 3 2 3 2 6 1 1 4 3 5 1 3 1 3 1 1 2 3 2 1 2 4 2 1 1 4 2 1 1 2 1 2 1 2 1 4 1 3 3 2 3 3 1 4 3 1 2 5 3 5 3 3 3 1 2 3 2 1 1 2 1 1 2 4 1 3 1 1 1 2 1 1 2 3 1 1 2 4 3 3 2 4 1 3 1 1 1 4 2 1 1 1 1 1 1 1 1 5 1 3 2 1 1 1 3 1 4 2 5 2 1 2 1 2 3 2 2 1 4 1 2 4 4 4 8 1 2 1 3 1 ...

output:

yes

result:

wrong answer expected NO, found YES