結果
問題 | No.1420 国勢調査 (Easy) |
ユーザー | Haa |
提出日時 | 2021-03-05 22:09:45 |
言語 | C++14 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 300 ms / 2,000 ms |
コード長 | 1,068 bytes |
コンパイル時間 | 1,941 ms |
コンパイル使用メモリ | 172,608 KB |
実行使用メモリ | 13,696 KB |
最終ジャッジ日時 | 2024-04-16 09:39:05 |
合計ジャッジ時間 | 8,773 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 5 ms
6,784 KB |
testcase_01 | AC | 5 ms
6,656 KB |
testcase_02 | AC | 132 ms
12,544 KB |
testcase_03 | AC | 132 ms
12,416 KB |
testcase_04 | AC | 131 ms
12,544 KB |
testcase_05 | AC | 131 ms
12,416 KB |
testcase_06 | AC | 132 ms
12,416 KB |
testcase_07 | AC | 119 ms
12,288 KB |
testcase_08 | AC | 118 ms
12,544 KB |
testcase_09 | AC | 118 ms
12,416 KB |
testcase_10 | AC | 119 ms
12,416 KB |
testcase_11 | AC | 121 ms
12,436 KB |
testcase_12 | AC | 20 ms
7,296 KB |
testcase_13 | AC | 146 ms
7,168 KB |
testcase_14 | AC | 20 ms
7,424 KB |
testcase_15 | AC | 147 ms
7,296 KB |
testcase_16 | AC | 149 ms
7,296 KB |
testcase_17 | AC | 149 ms
7,228 KB |
testcase_18 | AC | 148 ms
7,388 KB |
testcase_19 | AC | 148 ms
7,296 KB |
testcase_20 | AC | 149 ms
7,168 KB |
testcase_21 | AC | 150 ms
7,168 KB |
testcase_22 | AC | 294 ms
13,568 KB |
testcase_23 | AC | 292 ms
13,560 KB |
testcase_24 | AC | 300 ms
13,696 KB |
testcase_25 | AC | 296 ms
13,440 KB |
testcase_26 | AC | 300 ms
13,568 KB |
testcase_27 | AC | 164 ms
13,568 KB |
testcase_28 | AC | 159 ms
13,580 KB |
testcase_29 | AC | 161 ms
13,440 KB |
testcase_30 | AC | 162 ms
13,568 KB |
testcase_31 | AC | 164 ms
13,696 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef pair<ll,ll> P; typedef vector<ll> VI; typedef vector<VI> VVI; #define REP(i,n) for(int i=0;i<(n);i++) #define ALL(v) v.begin(),v.end() constexpr ll MOD=1000000007; constexpr ll INF=2e18; vector<vector<P>> edge(110000,vector<P>(0)); vector<bool> used(110000,0); VI ans(110000,-1); bool no=0; void dfs(int v, int x){ for(auto to:edge[v]){ if(ans[to.first]!=-1&&ans[to.first]!=(x^to.second)) no=1; if(!used[to.first]){ ans[to.first]=x^to.second; used[to.first]=1; dfs(to.first,x^to.second); } } } int main(){ int n, m; cin >> n >> m; int a, b, y; REP(i,m){ cin >> a >> b >> y; a--, b--; edge[a].push_back({b,y}); edge[b].push_back({a,y}); } REP(i,n){ if(!used[i]){ ans[i]=0; dfs(i,0); } } if(no) cout << -1 << endl; else{ REP(i,n) cout << ans[i] << endl; } return 0; }