Submission #884221

# Submission time Handle Problem Language Result Execution time Memory
884221 2023-12-06T19:07:51 Z vjudge1 Love Polygon (BOI18_polygon) C++17
29 / 100
189 ms 22356 KB
#include <bits/stdc++.h>
#define file_io freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define fast_io ios::sync_with_stdio(false);cin.tie(0);
#define what(x) cerr << #x << " is " << x << '\n';
#define kill(x) {cout << x << '\n'; return 0;}
#define all(x) (x).begin(), (x).end()
#define pii pair<int, int>
#define pb push_back
#define ll long long
#define F first
#define S second
const ll inf = 1e18, mod = 1e9 + 7, delta = 1e9 + 9, SQ = 450, P = 6065621;
 
using namespace std;

const ll N = 1e5 + 10, LG = 20;
vector<int> adj[N], r;
map<string, int> mp;
bitset<N> mark;
int dp[N][2];

void dfs (int v) {
  mark[v] = true;
  for (auto u: adj[v]) {
    if (!mark[u]) {
      dfs(u);
      dp[v][1] = max(dp[v][1] + max(dp[u][0], dp[u][1]), dp[v][0] + dp[u][0] + 1); 
      dp[v][0] += max(dp[u][0], dp[u][1]);
    }
  }
}

int main() {
  fast_io;
  int n = 0, m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    string s, t;
    cin >> s >> t;
    if (!mp[s]) 
      mp[s] = ++n;
    if (!mp[t]) 
      mp[t] = ++n;
    int v = mp[t], u = mp[s];
    if (v == u) {
      r.pb(u);
    }
    else {
      adj[u].pb(v);
      adj[v].pb(u);
    }
  }
  if (n & 1) kill(-1);
  int cnt = 0;
  // for (auto u: r) cout << u << ' ';
  for (auto u: r) {
    dfs(u);
    cnt += max(dp[u][0], dp[u][1]);
  }
  cout << n - cnt << '\n';
  return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Incorrect 1 ms 3420 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3420 KB Output is correct
2 Incorrect 1 ms 3420 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 173 ms 14416 KB Output is correct
2 Correct 156 ms 18060 KB Output is correct
3 Correct 120 ms 13768 KB Output is correct
4 Correct 153 ms 16416 KB Output is correct
5 Correct 175 ms 22356 KB Output is correct
6 Correct 189 ms 17040 KB Output is correct
7 Correct 148 ms 16804 KB Output is correct
8 Correct 144 ms 16080 KB Output is correct
9 Correct 159 ms 16972 KB Output is correct
10 Correct 119 ms 16724 KB Output is correct
11 Correct 1 ms 3416 KB Output is correct
12 Correct 1 ms 3420 KB Output is correct
13 Correct 1 ms 3416 KB Output is correct
14 Correct 1 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3416 KB Output is correct
2 Correct 1 ms 3420 KB Output is correct
3 Correct 1 ms 3420 KB Output is correct
4 Incorrect 1 ms 3420 KB Output isn't correct
5 Halted 0 ms 0 KB -