Submission #434019

# Submission time Handle Problem Language Result Execution time Memory
434019 2021-06-20T14:00:54 Z LouayFarah Love Polygon (BOI18_polygon) C++14
25 / 100
373 ms 24548 KB
#include "bits/stdc++.h"
using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef long long ll;
typedef string str;
typedef double db;
typedef long double ld;
typedef pair<int, int> pi;
#define fi first
#define se second

#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)

const ll MOD = 1e9 + 7; //998244353
const ll INF = 1e18;
const ll MX = 1e9 + 10;
const int nx[4] = {0, 0, 1, -1}, ny[4] = {1, -1, 0, 0}; //right left down up

#ifndef LOCAL
#define cerr if(false) cerr
#endif
#define debug(x) cerr << #x << " : " << x << endl;
#define debugs(x,y) cerr << #x << " : " << x << " / " << #y << " : " << y << endl;
#define debugv(v) cerr << #v << " : " << "[ "; for(auto it : v) cerr << it << ' '; cerr << ']' << endl;
#define here() cerr << "here" << endl;

void IO() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void dfs(vector<ll> adj[], vector<bool> &visited, ll u, ll &cnt)
{
    if(visited[u])
        return;
    visited[u] = true;
    cnt++;

    for(auto v: adj[u])
        dfs(adj, visited, v, cnt);
}

int main()
{
    boost;
    IO();

    ll n;
    cin >> n;

    map<string, ll> m;

    vector<ll> adj[n+1];
    vector<pair<string, string>> li;
    ll counter = 1;
    FOR(i, 0, n)
    {
        string a, b;
        cin >> a >> b;

        li.pb(mp(a, b));
        if(!m.count(a))
            m[a] = counter++;
        if(!m.count(b))
            m[b] = counter++;
    }

    FOR(i, 0, n)
    {
        string a = li[i].fi;
        string b = li[i].se;

        adj[m[a]].pb(m[b]);
    }


    vector<bool> visited(n+1, false);

    ll res = 0;
    ll odd = 0;
    for(int i = 1; i<=n; i++)
    {
        if(!visited[i])
        {
            ll cnt = 0;
            dfs(adj, visited, i, cnt);
            if(cnt%2==0)
            {
                if(cnt!=2)
                    res+=cnt/2;
            }
            else
                res+=cnt/2+1, odd++;
        }
    }

    if(odd%2==1)
        cout << -1 << endl;
    else
        cout << res << endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 338 ms 23900 KB Output is correct
5 Correct 373 ms 19824 KB Output is correct
6 Correct 310 ms 24548 KB Output is correct
7 Correct 355 ms 22056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 293 ms 19868 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -