Submission #9195266
Source Code Expand
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #define all(x) (x).begin(),(x).end() //#pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60; template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; } template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; } //--------------------------------------------------------------------------------------------------- struct UnionFind { using T = int; const T def = 0; T f(T a, T b) { return a + b; } //========================================== vector<int> par; vector<T> value; UnionFind() {} UnionFind(int NV) { init(NV); } void init(int NV) { par.clear(); rep(i, 0, NV) par.push_back(i); value.resize(NV, 1); } void reset() { rep(i, 0, par.size()) par[i] = i; } int operator[](int x) { if (par[x] == x) return x; else { int res = operator[](par[x]); if (res != par[x]) { value[res] = f(value[res], value[par[x]]); value[par[x]] = def; } return par[x] = res; } } // uf(x,y)->y void operator()(int x, int y) { x = operator[](x); y = operator[](y); if (x != y) { value[y] += value[par[x]]; value[par[x]] = def; par[x] = y; } } T getValues(int x) { return value[operator[](x)]; }; }; /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i @hamayanhamayan0 / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ int N, M, T; int X[101010], Y[101010]; #define UP '^' #define DOWN 'v' //--------------------------------------------------------------------------------------------------- using BS = bitset<50101>; BS dp[50101]; void solve1() { rep(i, 0, N) dp[i].set(i); rep(i, 0, M) dp[X[i]] = dp[Y[i]] = dp[X[i]] | dp[Y[i]]; rep(i, 0, N) if (dp[i].count() == N) { int goal = i; UnionFind uf(N); string ans = ""; rrep(j, M - 1, 0) { int g = uf[goal]; int x = uf[X[j]]; int y = uf[Y[j]]; if (g != x and g != y) ans += UP; else if (g == x and g == y) ans += UP; else if (g == x) { ans += UP; uf(x, y); } else { ans += DOWN; uf(x, y); } } reverse(all(ans)); cout << ans << endl; return; } cout << -1 << endl; } //--------------------------------------------------------------------------------------------------- int B[50101], cnt[50101]; void solve2() { if (N == 2) { cout << -1 << endl; return; } rep(i, 0, N) B[i] = i, cnt[i] = 1; string ans = ""; rrep(i, M - 1, 0) { int x = X[i], y = Y[i]; int bx = B[x], by = B[y]; if (cnt[bx] > cnt[by]) { ans += DOWN; cnt[by]++; cnt[bx]--; B[x] = by; } else { ans += UP; cnt[bx]++; cnt[by]--; B[y] = bx; } } reverse(all(ans)); cout << ans << endl; } //--------------------------------------------------------------------------------------------------- void _main() { cin >> N >> M >> T; rep(i, 0, M) { cin >> X[i] >> Y[i]; X[i]--, Y[i]--; } if (T == 1) solve1(); else solve2(); }
Submission Info
Submission Time | |
---|---|
Task | E - Balancing Network |
User | hamayanhamayan |
Language | C++14 (GCC 5.4.1) |
Score | 1600 |
Code Size | 3755 Byte |
Status | AC |
Exec Time | 411 ms |
Memory | 308860 KiB |
Judge Result
Set Name | Sample | Uniforming | Non-uniforming | ||||||
---|---|---|---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 800 / 800 | 800 / 800 | ||||||
Status |
|
|
|
Set Name | Test Cases |
---|---|
Sample | 00-sample-01.txt, 00-sample-02.txt, 00-sample-03.txt, 00-sample-04.txt |
Uniforming | 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, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, 01-41.txt, 01-42.txt, 01-43.txt, 01-44.txt, 01-45.txt, 01-46.txt, 01-47.txt, 01-48.txt, 01-49.txt, 01-50.txt, 01-51.txt, 01-52.txt, 01-53.txt, 01-54.txt, 01-55.txt |
Non-uniforming | 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, 02-17.txt, 02-18.txt, 02-19.txt, 02-20.txt, 02-21.txt, 02-22.txt, 02-23.txt, 02-24.txt, 02-25.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
00-sample-01.txt | AC | 2 ms | 2304 KiB |
00-sample-02.txt | AC | 2 ms | 2304 KiB |
00-sample-03.txt | AC | 2 ms | 2304 KiB |
00-sample-04.txt | AC | 2 ms | 2304 KiB |
01-01.txt | AC | 2 ms | 2304 KiB |
01-02.txt | AC | 2 ms | 2304 KiB |
01-03.txt | AC | 2 ms | 2304 KiB |
01-04.txt | AC | 2 ms | 2304 KiB |
01-05.txt | AC | 2 ms | 2304 KiB |
01-06.txt | AC | 2 ms | 2304 KiB |
01-07.txt | AC | 2 ms | 2304 KiB |
01-08.txt | AC | 116 ms | 3200 KiB |
01-09.txt | AC | 113 ms | 3072 KiB |
01-10.txt | AC | 118 ms | 3072 KiB |
01-11.txt | AC | 2 ms | 2304 KiB |
01-12.txt | AC | 2 ms | 2304 KiB |
01-13.txt | AC | 2 ms | 2304 KiB |
01-14.txt | AC | 2 ms | 2304 KiB |
01-15.txt | AC | 2 ms | 2304 KiB |
01-16.txt | AC | 2 ms | 2304 KiB |
01-17.txt | AC | 117 ms | 3200 KiB |
01-18.txt | AC | 117 ms | 3200 KiB |
01-19.txt | AC | 115 ms | 3200 KiB |
01-20.txt | AC | 8 ms | 10112 KiB |
01-21.txt | AC | 5 ms | 10112 KiB |
01-22.txt | AC | 5 ms | 10112 KiB |
01-23.txt | AC | 8 ms | 10112 KiB |
01-24.txt | AC | 8 ms | 10112 KiB |
01-25.txt | AC | 5 ms | 10112 KiB |
01-26.txt | AC | 137 ms | 10880 KiB |
01-27.txt | AC | 124 ms | 10880 KiB |
01-28.txt | AC | 131 ms | 10880 KiB |
01-29.txt | AC | 201 ms | 306560 KiB |
01-30.txt | AC | 201 ms | 306560 KiB |
01-31.txt | AC | 201 ms | 306560 KiB |
01-32.txt | AC | 203 ms | 307072 KiB |
01-33.txt | AC | 203 ms | 307072 KiB |
01-34.txt | AC | 203 ms | 307072 KiB |
01-35.txt | AC | 231 ms | 308220 KiB |
01-36.txt | AC | 199 ms | 308220 KiB |
01-37.txt | AC | 194 ms | 308860 KiB |
01-38.txt | AC | 281 ms | 307200 KiB |
01-39.txt | AC | 130 ms | 307836 KiB |
01-40.txt | AC | 135 ms | 307836 KiB |
01-41.txt | AC | 282 ms | 307200 KiB |
01-42.txt | AC | 271 ms | 307836 KiB |
01-43.txt | AC | 189 ms | 307836 KiB |
01-44.txt | AC | 152 ms | 307836 KiB |
01-45.txt | AC | 291 ms | 307200 KiB |
01-46.txt | AC | 151 ms | 307836 KiB |
01-47.txt | AC | 150 ms | 307836 KiB |
01-48.txt | AC | 411 ms | 307584 KiB |
01-49.txt | AC | 341 ms | 308220 KiB |
01-50.txt | AC | 322 ms | 308220 KiB |
01-51.txt | AC | 294 ms | 308220 KiB |
01-52.txt | AC | 365 ms | 308220 KiB |
01-53.txt | AC | 263 ms | 308220 KiB |
01-54.txt | AC | 285 ms | 308220 KiB |
01-55.txt | AC | 378 ms | 308220 KiB |
02-01.txt | AC | 2 ms | 2304 KiB |
02-02.txt | AC | 13 ms | 2816 KiB |
02-03.txt | AC | 14 ms | 3072 KiB |
02-04.txt | AC | 13 ms | 3072 KiB |
02-05.txt | AC | 14 ms | 3072 KiB |
02-06.txt | AC | 14 ms | 3072 KiB |
02-07.txt | AC | 15 ms | 3072 KiB |
02-08.txt | AC | 15 ms | 3072 KiB |
02-09.txt | AC | 15 ms | 3072 KiB |
02-10.txt | AC | 16 ms | 3072 KiB |
02-11.txt | AC | 16 ms | 3072 KiB |
02-12.txt | AC | 16 ms | 3072 KiB |
02-13.txt | AC | 16 ms | 3072 KiB |
02-14.txt | AC | 16 ms | 3072 KiB |
02-15.txt | AC | 16 ms | 3072 KiB |
02-16.txt | AC | 16 ms | 3072 KiB |
02-17.txt | AC | 16 ms | 3072 KiB |
02-18.txt | AC | 16 ms | 3072 KiB |
02-19.txt | AC | 16 ms | 3072 KiB |
02-20.txt | AC | 17 ms | 3072 KiB |
02-21.txt | AC | 18 ms | 3200 KiB |
02-22.txt | AC | 19 ms | 3456 KiB |
02-23.txt | AC | 15 ms | 3072 KiB |
02-24.txt | AC | 15 ms | 3072 KiB |
02-25.txt | AC | 16 ms | 3072 KiB |