Submission #00190
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | // "include" {{{ #include <deque> #include <iostream> #include <vector> #include <algorithm> #include <string> #include <deque> #include <list> #include <map> #include <queue> #include <set> #include <stack> #include <cstring> #include <utility> // }}} using namespace std; #define rep(i,n) for(int i=0;i<(n);++i) #define reps(i,n) for(int i=1;i<=(n);++i) #define all(x) (x).begin(),(x).end() //#define int long long #define pii pair<int,int> const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const long long mod = 1000000007; int gcd( int a, int b){ return b ? gcd(b,a%b) : a;} int lcm( int a, int b){ return a/gcd(a,b)*b;} struct UnionFind { vector < pii > par; vector < int > siz; UnionFind( int n): par(n), siz(n, 1) { //初期化 for ( int i = 1; i <= n; i++){ par[i].first = i; par[i].second = 0; } } int root( int x){ //根の更新+判定 if (par[x].first == x) return x; else return par[x].first = root(par[x].first); } int size( int x){ //サイズ return siz[root(x)]; } bool same( int c, int x){ //グループの判定 int tmp = root(par[c].first); if (par[tmp].second == 0){ par[tmp].second = x; return false ; } if (par[tmp].second == x){ return false ; } return true ; } bool unite( int x, int y){ //つなげる if ((x=root(x))==(y=root(y))) return false ; if ( siz[y] > siz[x] ) swap(x,y); siz[x] += siz[y]; if (par[x].second == 0 && par[y].second != 0){ par[y].first = x; par[x].second = par[y].second; return false ; } else if (par[x].second != par[y].second && par[y].second != 0 && par[x].second != 0){ return true ; } else { par[y].first = x; return false ; } } }; signed main(){ cin.tie(0); ios::sync_with_stdio( false ); int n,m,k; cin >> n >> m >> k; UnionFind uf(100050); vector< int > r(k + 10), a(k + 10), b(k + 10); reps(i, k) cin >> r[i] >> a[i] >> b[i]; reps(i,k){ if (r[i] == 1){ bool f1 = uf.unite(a[i],b[i]); if (f1){ cout << i << '\n' ; return 0; } } else { bool f1 = uf.same(a[i],b[i]); if (f1){ cout << i << '\n' ; return 0; } } } cout << 0 << '\n' ; return 0; } |
ステータス
項目 | データ |
---|---|
問題 | 0007 - 部活動調査 |
ユーザー名 | 虚無 |
投稿日時 | 2019-09-10 18:34:00 |
言語 | C++14 |
状態 | Accepted |
得点 | 13 |
ソースコード長 | 2307 Byte |
最大実行時間 | 46 ms |
最大メモリ使用量 | 4068 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 13 / 13 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
00-sample1.in | AC | 25 ms | 1756 KB |
1
|
00-sample2.in | AC | 20 ms | 1812 KB |
1
|
00-sample3.in | AC | 21 ms | 1872 KB |
1
|
01_small_00.in | AC | 25 ms | 1668 KB |
1
|
01_small_01.in | AC | 21 ms | 1724 KB |
1
|
01_small_02.in | AC | 17 ms | 1648 KB |
1
|
02_rand_00.in | AC | 16 ms | 1708 KB |
1
|
02_rand_01.in | AC | 21 ms | 1768 KB |
1
|
02_rand_02.in | AC | 20 ms | 1824 KB |
1
|
02_rand_03.in | AC | 18 ms | 1752 KB |
1
|
02_rand_04.in | AC | 17 ms | 1684 KB |
1
|
02_rand_05.in | AC | 20 ms | 1744 KB |
1
|
02_rand_06.in | AC | 21 ms | 1676 KB |
1
|
02_rand_07.in | AC | 17 ms | 1736 KB |
1
|
02_rand_08.in | AC | 21 ms | 1664 KB |
1
|
02_rand_09.in | AC | 20 ms | 1724 KB |
1
|
02_rand_10.in | AC | 21 ms | 1784 KB |
1
|
02_rand_11.in | AC | 18 ms | 1712 KB |
1
|
02_rand_12.in | AC | 26 ms | 1768 KB |
1
|
02_rand_13.in | AC | 24 ms | 1824 KB |
1
|
02_rand_14.in | AC | 28 ms | 1748 KB |
1
|
02_rand_15.in | AC | 26 ms | 1804 KB |
1
|
02_rand_16.in | AC | 22 ms | 1728 KB |
1
|
02_rand_17.in | AC | 24 ms | 1788 KB |
1
|
02_rand_18.in | AC | 21 ms | 1716 KB |
1
|
02_rand_19.in | AC | 27 ms | 1772 KB |
1
|
02_rand_20.in | AC | 22 ms | 1692 KB |
1
|
02_rand_21.in | AC | 17 ms | 1748 KB |
1
|
02_rand_22.in | AC | 25 ms | 1932 KB |
1
|
03_large_00.in | AC | 23 ms | 1860 KB |
1
|
03_large_01.in | AC | 17 ms | 1908 KB |
1
|
03_large_02.in | AC | 24 ms | 1900 KB |
1
|
03_large_03.in | AC | 46 ms | 4068 KB |
1
|
04_rand_large_zero_00.in | AC | 38 ms | 2928 KB |
1
|
50-random00.in | AC | 22 ms | 1808 KB |
1
|
50-random01.in | AC | 19 ms | 1808 KB |
1
|
50-random02.in | AC | 20 ms | 1960 KB |
1
|
50-random03.in | AC | 21 ms | 2028 KB |
1
|
50-random04.in | AC | 21 ms | 1848 KB |
1
|
50-random05.in | AC | 24 ms | 2052 KB |
1
|
50-random06.in | AC | 16 ms | 1888 KB |
1
|
50-random07.in | AC | 26 ms | 2100 KB |
1
|
50-random08.in | AC | 19 ms | 2004 KB |
1
|
50-random09.in | AC | 23 ms | 1988 KB |
1
|
max1.in | AC | 20 ms | 2044 KB |
1
|
maxn1.in | AC | 24 ms | 2176 KB |
1
|
maxn2.in | AC | 23 ms | 1996 KB |
1
|
maxn3.in | AC | 31 ms | 1928 KB |
1
|