結果

問題 No.1420 国勢調査 (Easy)
ユーザー ぷらぷら
提出日時 2021-03-05 22:50:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,693 bytes
コンパイル時間 1,992 ms
コンパイル使用メモリ 173,064 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2024-04-16 10:39:34
合計ジャッジ時間 17,079 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 AC 2 ms
5,376 KB
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pcc = pair<char,char>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using pdd = pair<ld,ld>;
using tuplis = array<ll,3>;
template<class T> using prique = priority_queue<T,vector<T>,greater<T>>;
#define rep(i,n) for(ll i = 0; i < n; i++)
#define rrep(i,n) for(ll i = n-1; i >= 0; i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define Sort(a) sort(all(a))
#define Rev(a) reverse(all(a))
#define Uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())
const ll LINF = 1001001001001001001;
const int INF = 1001001001;
const int MOD = 1000000007;
const int MODD = 998244353;
const ld PI = 3.1415926535897932;
const ll dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const ll dy[] = {1, 0, -1, 0, 1, 1, -1, -1};
inline ll popcnt(ll a){ return __builtin_popcountll(a); }
inline ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
inline ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll gcd(ll a,ll b){ if(a%b == 0){return b; } else{ return gcd(b,a%b); } }
ll lcm(ll a,ll b){ return a/gcd(a,b)*b; }
template<class T> bool chmin(T& a, const T& b){ if(a > b){ a = b; return 1; } return 0; }
template<class T> bool chmax(T& a, const T& b){ if(a < b){ a = b; return 1; } return 0; }
template<class T, class U> bool chmin(T& a, const U& b){ if(a > T(b)){ a = b; return 1; } return 0; }
template<class T, class U> bool chmax(T& a, const U& b){ if(a < T(b)){ a = b; return 1; } return 0; }
int main() {
    int N,M;
    cin >> N >> M;
    vector<int>ans(N,-1);
    vector<vector<pii>>road(N);
    rep(i,M) {
        int A,B,Y;
        cin >> A >> B >> Y;
        A--;B--;
        road[A].push_back({B,Y});
        road[B].push_back({A,Y});
    }
    rep(i,N) {
        if(ans[i] == -1) {
            ans[i] = 1;
            queue<int>que;
            que.push(i);
            while (!que.empty()) {
                int x = que.front();
                que.pop();
                for(int j = 0; j < road[x].size(); j++) {
                    if(ans[road[x][j].first] == -1) {
                        ans[road[x][j].first] = ans[x]^road[x][j].second;
                        que.push(ans[road[x][j].first]);
                    }
                    else {
                        if(ans[road[x][j].first] != (ans[x]^road[x][j].second)) {
                            cout << -1 << endl;
                            return 0;
                        }
                    }
                }
            }
        }
    }
    rep(i,N) {
        cout << ans[i] << endl;
    }
}
0