CSES - Datatähti 2024 loppu - Results
Submission details
Task:Peli
Sender:Vludo
Submission time:2024-10-14 01:39:31 +0300
Language:C++ (C++20)
Status:READY
Result:0
Feedback
groupverdictscore
#10
#20
Test results
testverdicttimegroup
#1ACCEPTED0.00 s1, 2details
#2ACCEPTED0.00 s1, 2details
#3ACCEPTED0.24 s2details
#4ACCEPTED0.00 s1, 2details
#50.00 s1, 2details
#6ACCEPTED0.22 s2details
#70.35 s2details
#80.01 s1, 2details
#9--2details
#10--2details

Code

#include<bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<n;++i)
#define inf ((int)1.01e9)
#define N 2505
typedef long long ll;
typedef pair<int,int> pii;

int n,m,q,z[N][N],oddz[N][N],Z[N];
vector<int> v[N]; 

// perus bfs
void haku(int S) {
    queue<pii> q;
    q.push({0,S});
    while(!q.empty()) {
        auto[e,s] = q.front();
        q.pop();
        e++;
        for (auto i : v[s]) {
            if (z[S][i]<e) {
                if (oddz[S][i]<e
                || (e&1)==(z[S][i]&1))
                    continue;
                oddz[S][i]=e;
                q.push({e,i});
                continue;
            }
            z[S][i]=e;
            q.push({e,i});
        }
    }
}
int main() {
    cin.tie(0)->sync_with_stdio(false);
    cout.tie(0);
    // freopen("test_input.txt", "r", stdin);
    // freopen("test_output.txt", "w", stdout);
    cin>>n>>m>>q; 
    int a,b,x;
    forn(i,m) {
        cin>>a>>b;
        v[a].push_back(b);
        v[b].push_back(a);
    }
    forn(i,n) fill(z[i+1],z[i+1]+n+1,inf);
    forn(i,n) fill(oddz[i+1],oddz[i+1]+n+1,inf);
    forn(i,n) z[i+1][i+1]=oddz[i+1][i+1]=0;

    // forn(i,n) haku(i+1);
    // forn(i,n) haku(i+1,true);

    /*
    // debug
    forn(i,n) {
        forn(j,n)
            cout<<z[i+1][j+1]<<' ';
        cout<<endl;
    }
    cout<<endl; 
    forn(i,n) {
        forn(j,n)
            cout<<oddz[i+1][j+1]<<' ';
        cout<<endl;
    }
    cout<<endl;
    //
    */

    forn(i,q) {
        cin>>a>>b>>x;
        if (!Z[a] && !Z[b]) {
            haku(a);
            Z[a]=1;
        }
        else if (!Z[a] && Z[b])
            swap(a,b);
        if (x>=z[a][b]) 
            if ((x&1)==((z[a][b])&1)||(x>=oddz[a][b]&&(x&1)==((oddz[a][b])&1))) {
                cout<<"YES\n"; continue;
            }
        cout<<"NO\n";
    }
}

Test details

Test 1

Group: 1, 2

Verdict: ACCEPTED

input
2 1 100
1 2
1 1 0
1 2 0
2 1 0
...

correct output
YES
NO
NO
YES
NO
...

user output
YES
NO
NO
YES
NO
...
Truncated

Test 2

Group: 1, 2

Verdict: ACCEPTED

input
50 49 100
33 34
7 8
49 50
47 48
...

correct output
NO
NO
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...
Truncated

Test 3

Group: 2

Verdict: ACCEPTED

input
2500 2499 100000
821 822
2351 2352
752 753
832 833
...

correct output
NO
YES
YES
NO
NO
...

user output
NO
YES
YES
NO
NO
...
Truncated

Test 4

Group: 1, 2

Verdict: ACCEPTED

input
12 12 100
9 10
2 3
1 12
1 2
...

correct output
NO
NO
NO
NO
NO
...

user output
NO
NO
NO
NO
NO
...
Truncated

Test 5

Group: 1, 2

Verdict:

input
11 11 100
10 11
7 8
1 2
5 6
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...
Truncated

Test 6

Group: 2

Verdict: ACCEPTED

input
2500 2500 100000
1936 1937
1884 1885
751 752
831 832
...

correct output
NO
YES
YES
NO
NO
...

user output
NO
YES
YES
NO
NO
...
Truncated

Test 7

Group: 2

Verdict:

input
2499 2499 100000
821 822
2351 2352
752 753
832 833
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...
Truncated

Test 8

Group: 1, 2

Verdict:

input
50 99 100
40 47
34 50
44 47
15 16
...

correct output
YES
YES
YES
YES
YES
...

user output
YES
YES
YES
YES
YES
...
Truncated

Test 9

Group: 2

Verdict:

input
2500 4999 100000
1191 2361
251 399
1026 2300
82 1655
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)

Test 10

Group: 2

Verdict:

input
2500 4999 100000
2023 2218
23 51
1020 1272
11 114
...

correct output
YES
YES
YES
YES
YES
...

user output
(empty)