Submission #858403

# Submission time Handle Problem Language Result Execution time Memory
858403 2023-10-08T11:23:55 Z jamkel Teoretičar (COCI18_teoreticar) C++14
26 / 130
12000 ms 64860 KB
#include <bits/stdc++.h>
using namespace std;
#define st first
#define nd second
typedef long long ll;
ll wynik=0;
bool dfs(vector<vector<pair<ll,ll>>>&a,vector<vector<pair<ll,ll>>>&b, vector<bool>&odwiedzone,bool czy,ll co)
{
    ll f=0;
    if(czy)
    {
        f+=a.size();
    }
    if(odwiedzone[co+f])
    {
        return false;
    }
    odwiedzone[co+f]=true;
    if(czy)
    {
        for(ll i=0;i<b[co].size();i++)
        {
            if(b[co][i].nd==wynik)
            {
                if(dfs(a,b,odwiedzone,false,b[co][i].st))
                {
                    b[co][i].nd=-1;                    
                    for(ll o=0;o<a[b[co][i].st].size();o++)
                    {
                        if(a[b[co][i].st][o].st==co)
                        {
                            a[b[co][i].st][o].nd=-1;
                            break;
                        }
                    }
                    return true;
                }
                return false;
            }
        }
        return true;

    }
    else
    {
        for(ll i=0;i<a[co].size();i++)
        {
            if(a[co][i].nd==-1)
            {
                if(dfs(a,b,odwiedzone,true,a[co][i].st))
                {
                    a[co][i].nd=wynik;
                    for(ll o=0;o<b[a[co][i].st].size();o++)
                    {
                        if(b[a[co][i].st][o].st==co)
                        {
                            b[a[co][i].st][o].nd=wynik;
                            break;
                        }
                    }
                    return true;
                }
            }
        
        }return false;
    }
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    ll l,r,m;
    cin>>l>>r>>m;
    vector<pair<ll,ll>>e(m);
    vector<vector<pair<ll,ll>>>a(l);
    vector<vector<pair<ll,ll>>>b(r);
   
   
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        x--;
        y--;
        a[x].push_back({y,-1});
        b[y].push_back({x,-1});
        e[i]={x,y};
    }    srand(time(NULL));
    
    ll ile=0;
    vector<ll>q(l);
    for(ll i=0;i<l;i++)
    {
        q[i]=i;
    }
    while(ile<m)
    {
    bool ok=true;
    vector<bool>w(l);
    random_shuffle(q.begin(),q.end());
    while(ok)
    {
        
        ok=false;
        vector<bool>odwiedzone(l+r);
        for(ll i=0;i<l;i++)
        {
            if(!w[q[i]])
            {
                if(dfs(a,b,odwiedzone,false,q[i]))
                {
                    ok=true;
                    ile++;
                    w[q[i]]=true;
                }
            }
        }
    }
    wynik++;
    }
    map<pair<ll,ll>,ll>ma;
    for(ll i=0;i<a.size();i++)
    {
        for(ll j=0;j<a[i].size();j++)
        {
            ma[{i,a[i][j].st}]=a[i][j].nd+1;
        }
    }
    cout<<wynik<<endl;
    for(ll i=0;i<m;i++)
    {
        cout<<ma[e[i]]<<endl;
    }
}

Compilation message

teoreticar.cpp: In function 'bool dfs(std::vector<std::vector<std::pair<long long int, long long int> > >&, std::vector<std::vector<std::pair<long long int, long long int> > >&, std::vector<bool>&, bool, ll)':
teoreticar.cpp:21:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(ll i=0;i<b[co].size();i++)
      |                    ~^~~~~~~~~~~~~
teoreticar.cpp:28:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |                     for(ll o=0;o<a[b[co][i].st].size();o++)
      |                                ~^~~~~~~~~~~~~~~~~~~~~~
teoreticar.cpp:46:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |         for(ll i=0;i<a[co].size();i++)
      |                    ~^~~~~~~~~~~~~
teoreticar.cpp:53:33: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |                     for(ll o=0;o<b[a[co][i].st].size();o++)
      |                                ~^~~~~~~~~~~~~~~~~~~~~~
teoreticar.cpp: In function 'int main()':
teoreticar.cpp:121:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::vector<std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |     for(ll i=0;i<a.size();i++)
      |                ~^~~~~~~~~
teoreticar.cpp:123:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |         for(ll j=0;j<a[i].size();j++)
      |                    ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 456 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1116 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1116 KB Output is correct
2 Incorrect 12 ms 1116 KB too many colors
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2246 ms 56372 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2631 ms 56832 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10540 ms 64860 KB Output is correct
2 Execution timed out 12048 ms 47496 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8575 ms 62548 KB Output is correct
2 Execution timed out 12037 ms 47984 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 12080 ms 22224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1665 ms 48396 KB Output is correct
2 Execution timed out 12011 ms 45888 KB Time limit exceeded
3 Halted 0 ms 0 KB -