Submission #876697

# Submission time Handle Problem Language Result Execution time Memory
876697 2023-11-22T08:36:29 Z huynhyen1609 Experimental Charges (NOI19_charges) C++14
14 / 100
711 ms 10928 KB
#include<bits/stdc++.h>
using namespace std;
#define NAME ""
//#define int long long
const int N=2e5;
int n,q,p[N+5],a[N+5];
vector<int>vec[N+5];
int find(int v)
{
    if(p[v]==0)return v;
    return p[v]=find(p[v]);
}
void union_(int u,int v,int c)
{
    int x=u,y=v;
    u=find(u);v=find(v);
    if(u==v)return;
    if(vec[u].size()<vec[v].size())
    {
        swap(u,v);
        swap(x,y);
    }
    p[v]=u;
    for(int i:vec[v])vec[u].push_back(i);
    if(c!=(a[x]^a[y]))for(int i:vec[u])a[i]=1-a[i];
}
main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    //freopen(""NAME".inp","r",stdin);
    //freopen(""NAME".out","w",stdout);
    cin>>n>>q;
    for(int i=1;i<=n;++i)
    {
        a[i]=1;
        vec[i].push_back(i);
    }
    while(q--)
    {
        char c;
        int x,y;
        cin>>c>>x>>y;
        if(c=='R')union_(x,y,0);
        if(c=='A')union_(x,y,1);
        if(c=='Q')
        {
            if(find(x)!=find(y))cout<<"?\n";
            else
            {
                if((a[x]^a[y])==1)cout<<"A\n";
                else cout<<"R\n";
            }
        }
    }
}

Compilation message

charges.cpp:27:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   27 | main()
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Incorrect 1 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 711 ms 10160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10456 KB Output is correct
2 Correct 20 ms 10528 KB Output is correct
3 Correct 24 ms 10652 KB Output is correct
4 Correct 24 ms 10700 KB Output is correct
5 Correct 25 ms 10928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 365 ms 10220 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Incorrect 1 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Incorrect 1 ms 4956 KB Output isn't correct
3 Halted 0 ms 0 KB -