#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;
for(int i = 1; i<=n; i++)
{
if(!visited[i])
{
ll cnt = 0;
dfs(adj, visited, i, cnt);
if(cnt%2==0)
res+=cnt/2;
else
res+=cnt/2+1;
}
}
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 |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
299 ms |
19864 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 |
- |