Submission #1026919

# Submission time Handle Problem Language Result Execution time Memory
1026919 2024-07-18T13:43:27 Z 12345678 Love Polygon (BOI18_polygon) C++17
29 / 100
228 ms 27220 KB
#include <bits/stdc++.h>

using namespace std;

const int nx=1e5+5;

int n, t, vs[nx], l[nx], res, cnt, lv[nx], used[nx];
string su[nx], sv[nx];
map<string, int> mp;
vector<int> d[nx];

void dfs(int u, int p)
{
    for (auto v:d[u]) if (v!=p) dfs(v, u);
    if (u!=p&&!used[u]&&!used[p]) res--, used[u]=used[p]=1; 
}

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n;
    res=n;
    for (int i=1; i<=n; i++) cin>>su[i]>>sv[i], mp[su[i]]=mp[sv[i]]=0;
    if (n%2) return cout<<-1, 0;
    for (auto &[x, y]:mp) y=++t;
    for (int i=1; i<=n; i++) if (mp[su[i]]!=mp[sv[i]]) lv[mp[su[i]]]=1, d[mp[sv[i]]].push_back(mp[su[i]]);
    for (int i=1; i<=n; i++) if (!lv[i]) dfs(i, i);
    cout<<res;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Incorrect 1 ms 9052 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Incorrect 3 ms 9052 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 207 ms 19800 KB Output is correct
2 Correct 224 ms 23356 KB Output is correct
3 Correct 114 ms 18832 KB Output is correct
4 Correct 79 ms 19028 KB Output is correct
5 Correct 213 ms 27220 KB Output is correct
6 Correct 228 ms 21332 KB Output is correct
7 Correct 189 ms 21488 KB Output is correct
8 Correct 151 ms 20968 KB Output is correct
9 Correct 185 ms 20956 KB Output is correct
10 Correct 148 ms 20076 KB Output is correct
11 Correct 2 ms 9080 KB Output is correct
12 Correct 1 ms 9052 KB Output is correct
13 Correct 1 ms 9052 KB Output is correct
14 Correct 1 ms 9068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 9048 KB Output is correct
2 Correct 2 ms 9052 KB Output is correct
3 Correct 2 ms 9048 KB Output is correct
4 Incorrect 1 ms 9052 KB Output isn't correct
5 Halted 0 ms 0 KB -