답안 #880819

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
880819 2023-11-30T05:56:55 Z vjudge1 Love Polygon (BOI18_polygon) C++17
25 / 100
41 ms 8924 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 = 2e5 + 10, LG = 31;
int go[N], c;
unordered_map<string, int> com;
bool mark[N];

void dfs (int v) {
  c++;
  mark[v] = true;
  if (!mark[go[v]]) 
    dfs(go[v]);
}

int main() {
  fast_io;
  int m, n = 0;
  cin >> m;
  while (m--) {
    string s, t;
    cin >> s >> t;
    if (!com[s]) com[s] = ++n;
    if (!com[t]) com[t] = ++n;
    go[com[s]] = com[t];
  }
  if (n & 1) kill(-1);
  vector<int> cnt;
  for (int i = 1; i <= n; i++)
    if (!mark[i]) 
      c = 0, dfs(i), cnt.pb(c);
  int ans = 0;
  int cntt = 0;
  for (auto u: cnt) {
    if (u == 2) continue;
    if (u & 1) cntt++;
    ans += u / 2;
  }
  ans += cntt;
  cout << ans << '\n';
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 41 ms 8412 KB Output is correct
5 Correct 39 ms 8564 KB Output is correct
6 Correct 41 ms 8540 KB Output is correct
7 Correct 39 ms 8232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 40 ms 8924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -