Submission #305193

# Submission time Handle Problem Language Result Execution time Memory
305193 2020-09-22T17:22:44 Z Nayna Love Polygon (BOI18_polygon) C++14
0 / 100
402 ms 18040 KB
#include <bits/stdc++.h>

using namespace std;

const int mxn = 2e5+5;

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int,int>pii;
typedef pair<int,pii>piii;

#define  sf scanf
#define  pf printf

#define  input freopen("in.txt","r",stdin)
#define  output freopen("out.txt","w",stdout)

#define  inf 1e18
#define  ff first
#define  ss second
#define  MP make_pair
#define  pb push_back
#define  all(v) v.begin(), v.end()
#define  printcase(cases) printf("Case %d:", cases);
#define  Unique(a) a.erase(unique(a.begin(),a.end()),a.end())
#define  FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define  endl printf("\n")
#define  __lcm(a, b) ((a*b)/__gcd(a, b))

map<string,int>mark;
//vector<pii>edge;
int vis[mxn];
int in[mxn];
int cnt = 0;
int dir[mxn];
vector<int>adj[mxn];
void clear_all()
{
    for(int i = 0; i < mxn; i++) adj[i].clear();
    memset(vis, 0, sizeof vis);
}
void dfs(int u)
{
    vis[u] = 1;
    cnt++;
    for(auto v : adj[u])
    {
        if(vis[v]) continue;
        dfs(v);
    }
}
int main()
{
    //input;
   // output;

    int n;
    scanf("%d", &n);
    int pos = 1;
    vector<int>st;
    clear_all();
    for(int i = 0; i < n; i++)
    {
        string a, b;
        cin >> a >> b;

        if(!mark[a]) mark[a] = pos++;
        if(!mark[b]) mark[b] = pos++;

        int u = mark[a];
        int v = mark[b];
        in[v]++;
        dir[u] = v;
        //cout << u << ' ' << v << '\n';
        adj[u].push_back(v);
        //edge.push_back({u, v});
    }
    if(n&1)
    {
        cout << "-1\n";
        return 0;
    }
    int ans = 0;
    for(int i = 1; i <= n; i++)
    {
        if(dir[i]==i && in[i]==1) ans++;
        if(in[i]==0) st.push_back(i);
    }
    
    for(auto i : st)
    {
        cnt = 0;
        dfs(i);
        double x = cnt*1.0;
        ans+=ceil((x*1.0)/2);
    }
    cout << ans << '\n';
    return 0;
}

Compilation message

polygon.cpp: In function 'int main()':
polygon.cpp:59:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   59 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5760 KB Output is correct
2 Correct 4 ms 5760 KB Output is correct
3 Correct 4 ms 5760 KB Output is correct
4 Incorrect 4 ms 5760 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5760 KB Output is correct
2 Correct 4 ms 5760 KB Output is correct
3 Incorrect 4 ms 5760 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 402 ms 18040 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 5760 KB Output is correct
2 Correct 4 ms 5760 KB Output is correct
3 Correct 4 ms 5760 KB Output is correct
4 Incorrect 4 ms 5760 KB Output isn't correct
5 Halted 0 ms 0 KB -