Submission #797038

# Submission time Handle Problem Language Result Execution time Memory
797038 2023-07-29T05:07:13 Z vjudge1 Making Friends on Joitter is Fun (JOI20_joitter2) C++14
0 / 100
2 ms 4948 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define ll long long
using namespace std ;
const ll N = 1e5 ;
ll ans, cnt[N + 1] ;
map<pair<ll, ll>, bool> mp ;
vector<int> v[N + 1], v1[N + 1] ;
signed main()
{
    ios_base::sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
    ll n, m ;
    cin >> n >> m ;
    if(n <= 2000)
    {
        while(m--)
        {
            ll x, y ;
            cin >> x >> y ;
            if(!mp[{x, y}])
            {
                ans++ ;
                mp[{x, y}] = 1 ;
                v[x].push_back(y) ;
                v1[y].push_back(x) ;
//                cout<<x<<"->"<<y << '\n' ;
            }
            deque<pair<int, int>> d ;
            if(mp[{x, y}] && mp[{y, x}])
                d.push_back({x, y}) ;
            while(d.size())
            {
                int x1 = d[0].fi, y1 = d[0].se ;
                d.pop_front() ;
                for(ll i = 0 ; i < v1[y1].size() ; i++)
                {
                    ll z = v1[y1][i] ;
                    if(z != x1 && !mp[{z, x1}])
                    {
                        mp[{z, x1}] = 1 ;
                        if(mp[{x1, z}])
                            d.push_back({z, x1}) ;
                        ans++ ;
                        v[z].push_back(x1) ;
//                        cout<<z<<"->"<<x1 << '\n' ;
                        v1[x1].push_back(z) ;
                    }
                }
                for(ll i = 0 ; i < v1[x1].size() ; i++)
                {
                    ll z = v1[x1][i] ;
                    if(z != y1 && !mp[{z, y1}])
                    {
                        mp[{z, y1}] = 1 ;
                        if(mp[{z, y1}])
                            d.push_back({z, y1}) ;
                        ans++ ;
                        v[z].push_back(y1) ;
//                        cout<<z<<"->"<<y1 << '\n' ;
                        v1[y1].push_back(z) ;
                    }
                }
                for(ll i = 0 ; i < v[y1].size() ; i++)
                {
                    ll z = v[y1][i] ;
                    if(z != x1 && !mp[{x1, z}] && mp[{z, y1}])
                    {
                        mp[{x1, z}] = 1 ;
                        ans++ ;
                        v[z].push_back(x1) ;
//                        cout<<z<<"->"<<x1 << '\n' ;
                        v1[x1].push_back(z) ;
                    }
                }
            }
            for(ll i = 0 ; i < v[y].size() ; i++)
            {
                ll z = v[y][i] ;
                if(z != x && !mp[{x, z}] && mp[{z, y}])
                {
                    mp[{x, z}] = 1 ;
                    ans++ ;
                    v[z].push_back(x) ;
//                        cout<<z<<"->"<<x << '\n' ;
                    v1[x].push_back(z) ;
                }
            }
            cout << ans << '\n' ;
        }
        return 0 ;
    }
    for(ll i = 1 ; i <= m ; i++)
    {
        ll x, y ;
        cin >> x >> y ;
        cout << ans << '\n' ;
    }
    return 0 ;
}

Compilation message

joitter2.cpp: In function 'int main()':
joitter2.cpp:38:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |                 for(ll i = 0 ; i < v1[y1].size() ; i++)
      |                                ~~^~~~~~~~~~~~~~~
joitter2.cpp:52:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |                 for(ll i = 0 ; i < v1[x1].size() ; i++)
      |                                ~~^~~~~~~~~~~~~~~
joitter2.cpp:66:34: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |                 for(ll i = 0 ; i < v[y1].size() ; i++)
      |                                ~~^~~~~~~~~~~~~~
joitter2.cpp:79:30: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |             for(ll i = 0 ; i < v[y].size() ; i++)
      |                            ~~^~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 4948 KB Output isn't correct
2 Halted 0 ms 0 KB -