Submission #880883

#TimeUsernameProblemLanguageResultExecution timeMemory
880883vjudge1Love Polygon (BOI18_polygon)C++17
0 / 100
63 ms19864 KiB
#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], cnt[N], c, ans, bad, b[N], par[N]; unordered_map<string, int> tmpMadarJende; bool mark[N], in[N], state[N]; vector<int> back[N]; void dfs (int v, int p = -1) { par[v] = p; if (!back[v].size() && !state[p]) { ++ans; // what(p); // what(v); b[par[p]]++; b[p]++; state[p] = true; state[v] = true; return; } for (auto u: back[v]) { if (u - p) dfs(u, v); } if (state[p] && b[v] == back[v].size()) { ++bad; return; } } int main() { fast_io; int m, n = 0; cin >> m; while (m--) { string s, t; cin >> s >> t; if (!tmpMadarJende[s]) tmpMadarJende[s] = ++n; if (!tmpMadarJende[t]) tmpMadarJende[t] = ++n; if (s == t) in[tmpMadarJende[s]] = true; else { cnt[tmpMadarJende[t]]++; go[tmpMadarJende[s]] = tmpMadarJende[t]; back[tmpMadarJende[t]].pb(tmpMadarJende[s]); } } if (n & 1) kill(-1); for (int i = 1; i <= n; i++) { if (in[i] && !cnt[i]) { ++bad; continue; } if (in[i]) dfs(i); } cout << bad + ans << '\n'; // what(bad); // what(ans); return 0; }

Compilation message (stderr)

polygon.cpp: In function 'void dfs(int, int)':
polygon.cpp:37:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |   if (state[p] && b[v] == back[v].size()) {
      |                   ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...