Submission #4635412


Source Code Expand

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
struct UnionFind {
    vector<int> data;
    UnionFind(int size) : data(size,-1) { }

    int root(int x){
        if (data[x] < 0) return x;
        else return data[x] = root(data[x]);
    }

    int size(int x){
        return -data[root(x)];
    }

    bool isConnect(int x,int y){
        return root(x) == root(y);
    }

    bool connect(int x , int y){
        x = root(x);
        y = root(y);

        if(x==y) return false;

        if(data[x] > data[y]){
            x ^= y;
            y ^= x;
            x ^= y;
        }

        data[x] = data[x] + data[y]; // membersize++
        data[y] = x;
        return true;
    }
};

int main() {
    UnionFind U(100002);
    int N,M;
    SCD2(N,M);
    vector< pair<int,PII> >yab;
    int Q;

    vector< pair<int,PII> >wvQ;
    static int ans[100002]={};

    REP(i,M){
        int a,b,y;
        SCD3(a,b,y);
        PII ab = MP(a,b);
        yab.PB(MP(y,ab));
    }

    SCD(Q);

    REP(i,Q){
        int v,w;
        SCD2(v,w);
        PII vQ = MP(v,i+1);
        wvQ.PB(MP(w,vQ));
    }

    sort(ALL(yab)); reverse(ALL(yab));
    sort(ALL(wvQ)); reverse(ALL(wvQ));

    int Qin = 0;
    int rin = 0;

    while(Qin < Q){
        int a,b,y,v,w,Qn;
        if (rin < M) {
            a = yab[rin].snd.fst;
            b = yab[rin].snd.snd;
            y = yab[rin].fst;
        }else{
            y = -1;
            a = b = 0;
        }


        w = wvQ[Qin].fst;
        v = wvQ[Qin].snd.fst;
        Qn = wvQ[Qin].snd.snd;

        if (y > w){
            U.connect(a,b);
            rin++;
        }else{
            ans[Qn] = U.size(v);
            Qin++;
        }
    }

    REP(i,Q){
        PRINTD(ans[i+1]);
    }


}

Submission Info

Submission Time
Task D - 道路の老朽化対策について
User Lithium
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3567 Byte
Status AC
Exec Time 107 ms
Memory 7024 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:94:14: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     SCD2(N,M);
              ^
./Main.cpp:103:20: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         SCD3(a,b,y);
                    ^
./Main.cpp:108:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
     SCD(Q);
           ^
./Main.cpp:112:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         SCD2(v,w);
                  ^

Judge Result

Set Name Sample Subtask1 All
Score / Max Score 0 / 0 50 / 50 50 / 50
Status
AC × 3
AC × 10
AC × 22
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
Subtask1 sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt
All sample_01.txt, sample_02.txt, sample_03.txt, subtask1_01.txt, subtask1_02.txt, subtask1_03.txt, subtask1_04.txt, subtask1_05.txt, subtask1_06.txt, subtask1_07.txt, subtask2_01.txt, subtask2_02.txt, subtask2_03.txt, subtask2_04.txt, subtask2_05.txt, subtask2_06.txt, subtask2_07.txt, subtask2_08.txt, subtask2_09.txt, subtask2_10.txt, subtask2_11.txt, subtask2_12.txt
Case Name Status Exec Time Memory
sample_01.txt AC 1 ms 640 KB
sample_02.txt AC 1 ms 640 KB
sample_03.txt AC 1 ms 640 KB
subtask1_01.txt AC 2 ms 640 KB
subtask1_02.txt AC 2 ms 640 KB
subtask1_03.txt AC 2 ms 640 KB
subtask1_04.txt AC 2 ms 640 KB
subtask1_05.txt AC 2 ms 640 KB
subtask1_06.txt AC 2 ms 640 KB
subtask1_07.txt AC 2 ms 640 KB
subtask2_01.txt AC 103 ms 6512 KB
subtask2_02.txt AC 104 ms 6768 KB
subtask2_03.txt AC 104 ms 6512 KB
subtask2_04.txt AC 107 ms 6512 KB
subtask2_05.txt AC 54 ms 4084 KB
subtask2_06.txt AC 99 ms 6640 KB
subtask2_07.txt AC 100 ms 6640 KB
subtask2_08.txt AC 100 ms 6640 KB
subtask2_09.txt AC 104 ms 7024 KB
subtask2_10.txt AC 105 ms 6512 KB
subtask2_11.txt AC 105 ms 6384 KB
subtask2_12.txt AC 102 ms 6512 KB