Submission #5474239


Source Code Expand

Copy
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define LINF 1e18
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }


int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

vector<vector<ll>> tree;
bool visit[10101];
bool white[10101];
vector<vector<ll>> length;

void dfs(int n,int sum){
    if(visit[n]) return;
    visit[n]=true;
    for(int i=0;i<tree[n].size();i++){
        sum+=length[n][tree[n][i]];
        //cout<<tree[n][i]<<":"<<sum<<endl;
        //cout<<sum<<endl;
        if(sum%2==0) white[tree[n][i]]=true;
        dfs(tree[n][i],sum);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;cin>>N;
    tree.resize(N+1);
    length.assign(N+1,vector<ll>(N+1));

    REP(i,N-1){
        visit[i]=false;
        ll u,v,w;
        cin>>u>>v>>w;
        tree[u-1].push_back(v-1);
        //tree[v-1].push_back(u-1);
        length[u-1][v-1]=length[u-1][v-1]=w;
    }
    white[0]=true;
    dfs(0,0);
    REP(i,N){
        if(white[i]) cout<<0<<endl;
        else cout<<1<<endl;
    }
}

Submission Info

Submission Time
Task D - Pair Cards
User Bondo416
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1712 Byte
Status
Exec Time 2632 ms
Memory 86900 KB

Judge Result

Set Name Score / Max Score Test Cases
sample 0 / 0 sample-01.txt, sample-02.txt
all 0 / 700 sample-01.txt, sample-02.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, sample-01.txt, sample-02.txt
Case Name Status Exec Time Memory
01-01.txt 97 ms 256 KB
01-02.txt 1800 ms -675392 KB
01-03.txt 1732 ms -675612 KB
01-04.txt 1930 ms -675496 KB
01-05.txt 1686 ms -675488 KB
01-06.txt 1982 ms -675600 KB
01-07.txt 1952 ms -675488 KB
01-08.txt 2632 ms -675484 KB
01-09.txt 2064 ms -675360 KB
01-10.txt 1784 ms -675224 KB
01-11.txt 1785 ms -675020 KB
01-12.txt 2057 ms -674988 KB
01-13.txt 1874 ms -674844 KB
01-14.txt 1707 ms -675184 KB
01-15.txt 1785 ms -675112 KB
01-16.txt 1791 ms -675108 KB
01-17.txt 1975 ms -675048 KB
01-18.txt 1719 ms -675108 KB
01-19.txt 1690 ms -675132 KB
01-20.txt 1787 ms -675132 KB
01-21.txt 1844 ms -674984 KB
01-22.txt 1777 ms -675000 KB
01-23.txt 2037 ms -674968 KB
01-24.txt 1783 ms -675080 KB
01-25.txt 1691 ms -675016 KB
01-26.txt 1786 ms -675164 KB
01-27.txt 1791 ms -675036 KB
01-28.txt 454 ms 86900 KB
01-29.txt 99 ms 2816 KB
01-30.txt 98 ms 256 KB
sample-01.txt 96 ms 256 KB
sample-02.txt 96 ms 256 KB