• 【[Offer收割]编程练习赛14 C】可疑的记录


    【题目链接】:http://hihocoder.com/problemset/problem/1507

    【题意】

    【题解】

    如果多出来一个的话;
    某个人的父亲节点就会变成两个
    找到有两个父亲节点的人就好;
    这张图有强制1号节点为根节点,且有强制父亲节点和儿子节点的层次关系;
    所以不能按照找环的思路来做;
    另外如果1号节点有父亲节点,则直接输出那条边就好;

    【Number Of WA

    4

    【完整代码】

    #include <bits/stdc++.h>
    using namespace std;
    #define lson l,m,rt<<1
    #define rson m+1,r,rt<<1|1
    #define LL long long
    #define rep1(i,a,b) for (int i = a;i <= b;i++)
    #define rep2(i,a,b) for (int i = a;i >= b;i--)
    #define mp make_pair
    #define pb push_back
    #define fi first
    #define se second
    #define ms(x,y) memset(x,y,sizeof x)
    
    typedef pair<int,int> pii;
    typedef pair<LL,LL> pll;
    
    const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
    const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
    const double pi = acos(-1.0);
    const int N = 1e5+100;
    
    vector <pii> fa[N];
    int n;
    
    int main()
    {
        //freopen("F:\rush.txt","r",stdin);
        ios::sync_with_stdio(false);
        cin >> n;
        rep1(i,1,n)
        {
            int x,y;
            cin >>x >>y;
            if (y==1) return cout << i << endl,0;
            fa[y].pb(mp(x,i));
        }
        rep1(i,1,n)
        {
            int len = fa[i].size();
            if (len>1)
            {
                cout << fa[i][0].se << ' '<< fa[i][1].se<<endl;
                return 0;
            }
        }
        //printf("
    %.2lf sec 
    ", (double)clock() / CLOCKS_PER_SEC);
        return 0;
    }
    
  • 相关阅读:
    6.24Java网络编程之IP
    Network
    Network
    Network
    Network
    ES
    JavaWeb
    ES
    ES
    ES
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626414.html
Copyright © 2020-2023  润新知