Submission #858399

# Submission time Handle Problem Language Result Execution time Memory
858399 2023-10-08T11:06:07 Z jamkel Teoretičar (COCI18_teoreticar) C++14
26 / 130
12000 ms 68828 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};
    }
    
    ll ile=0;
    while(ile<m)
    {
    bool ok=true;
    vector<bool>w(l);
    vector<ll>q(l);
    srand((unsigned) time(NULL));
     random_shuffle(q.begin(),q.end());
    for(ll i=0;i<l;i++)
    {
        q[i]=i;
    }
    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:122: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]
  122 |     for(ll i=0;i<a.size();i++)
      |                ~^~~~~~~~~
teoreticar.cpp:124: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]
  124 |         for(ll j=0;j<a[i].size();j++)
      |                    ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 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 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 1296 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 Correct 12 ms 1116 KB Output is correct
3 Correct 11 ms 1368 KB Output is correct
4 Incorrect 8 ms 1116 KB too many colors
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2256 ms 57352 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2531 ms 58084 KB too many colors
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10608 ms 68828 KB Output is correct
2 Execution timed out 12022 ms 54984 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8687 ms 66516 KB Output is correct
2 Execution timed out 12007 ms 55396 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 12091 ms 27188 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1670 ms 51236 KB Output is correct
2 Execution timed out 12075 ms 53476 KB Time limit exceeded
3 Halted 0 ms 0 KB -