3 条题解

  • 2
    @ 2019-01-24 11:47:47
    /*
    
    */
    #define method_1
    #ifdef method_1
    /*
    
    */
    #include<iostream>
    #include<vector>
    #include<cstring>
    const int maxn=50005*3;
    using namespace std;
    int n,k,pa[maxn],d,x,y;
    int cnt=0;
    int find(int x) {
        return pa[x]==x?x:pa[x]=find(pa[x]);
    }
    void link(int x,int y) {
        int fa=find(x);
        int fb=find(y);
        if(fa!=fb)
            pa[fa]=fb;
        return;
    }
    int main() {
        ios::sync_with_stdio(false);
    //  freopen("第一个早晨.in","r",stdin);
        cin>>n>>k;
        for(int i=1; i<=3*n; i++)
            pa[i]=i;
        for(int i=1; i<=k; i++) {
            cin>>d>>x>>y;
            if(x>n||y>n) {
                cnt++;
                continue;
            }
            if(d==1) {
                if(find(x)==find(y+n)||find(x+n)==find(y+2*n)) {
                    cout<<1;
                    return 0;
                }
                link(x,y);
                link(x+n,y+n);
                link(x+2*n,y+2*n);
            }
            if(d==2) {
                if(find(x)==find(y)||find(x)==find(y+2*n)) {
                    cout<<1;
                    return 0;
                }
                link(x,y+n);
                link(x+n,y+2*n);
                link(x+2*n,y);
            }
        }
        cout<<0;
        return 0;
    }
    #endif
    #ifdef method_2
    /*
    
    */
    
    #endif
    #ifdef method_3
    /*
    
    */
    
    #endif
    
    
  • 0

    #define method_1
    #ifdef method_1
    /*

    */
    #include<iostream>
    #include<vector>
    #include<cstring>
    const int maxn=50005*3;
    using namespace std;
    int n,k,pa[maxn],d,x,y;
    int cnt=0;
    int find(int x) {
    return pa[x]==x?x:pa[x]=find(pa[x]);
    }
    void link(int x,int y) {
    int fa=find(x);
    int fb=find(y);
    if(fa!=fb)
    pa[fa]=fb;
    return;
    }
    int main() {
    ios::sync_with_stdio(false);
    // freopen("第一个早晨.in","r",stdin);
    cin>>n>>k;
    for(int i=1; i<=3*n; i++)
    pa[i]=i;
    for(int i=1; i<=k; i++) {
    cin>>d>>x>>y;
    if(x>n||y>n) {
    cnt++;
    continue;
    }
    if(d==1) {
    if(find(x)==find(y+n)||find(x+n)==find(y+2*n)) {
    cout<<1;
    return 0;
    }
    link(x,y);
    link(x+n,y+n);
    link(x+2*n,y+2*n);
    }
    if(d==2) {
    if(find(x)==find(y)||find(x)==find(y+2*n)) {
    cout<<1;
    return 0;
    }
    link(x,y+n);
    link(x+n,y+2*n);
    link(x+2*n,y);
    }
    }
    cout<<0;
    return 0;
    }
    #endif
    #ifdef method_2
    /*

    */

    #endif
    #ifdef method_3
    /*

    */

    #endif

  • -1

    /*

    /
    #define method_1
    #ifdef method_1
    /

    */
    #include<iostream>
    #include<vector>
    #include<cstring>
    const int maxn=50005*3;
    using namespace std;
    int n,k,pa[maxn],d,x,y;
    int cnt=0;
    int find(int x) {
    return pa[x]==x?x:pa[x]=find(pa[x]);
    }
    void link(int x,int y) {
    int fa=find(x);
    int fb=find(y);
    if(fa!=fb)
    pa[fa]=fb;
    return;
    }
    int main() {
    ios::sync_with_stdio(false);
    // freopen("第一个早晨.in","r",stdin);
    cin>>n>>k;
    for(int i=1; i<=3*n; i++)
    pa[i]=i;
    for(int i=1; i<=k; i++) {
    cin>>d>>x>>y;
    if(x>n||y>n) {
    cnt++;
    continue;
    }
    if(d==1) {
    if(find(x)==find(y+n)||find(x+n)==find(y+2*n)) {
    cout<<1;
    return 0;
    }
    link(x,y);
    link(x+n,y+n);
    link(x+2*n,y+2*n);
    }
    if(d==2) {
    if(find(x)==find(y)||find(x)==find(y+2*n)) {
    cout<<1;
    return 0;
    }
    link(x,y+n);
    link(x+n,y+2*n);
    link(x+2*n,y);
    }
    }
    cout<<0;
    return 0;
    }
    #endif
    #ifdef method_2
    /*

    */

    #endif
    #ifdef method_3
    /*

    */

    #endif

  • 1

信息

难度
6
分类
(无)
标签
(无)
递交数
48
已通过
14
通过率
29%
被复制
4
上传者