Submission #35518032


Source Code Expand

/*
    Template Version: 1.0.0 - 20220620
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define ALL(a) a.begin(), a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define TRAV(x, a) for (auto &x : a)

using namespace std;
using ll = long long; using ld = double; 
using pi = pair<int, int>; using pl = pair<ll, ll>; using pd = pair<ld, ld>;
using cd = complex<ld>; using vcd = vector<cd>;

using vi = vector<int>; using vl = vector<ll>;
using vd = vector<ld>; using vs = vector<string>;
using vpi = vector<pi>; using vpl = vector<pl>; using vpd = vector<pd>; // vector<pair>

template<class T> using min_pq = priority_queue<T, vector<T>, greater<T> >;
template<class T> inline int ckmin(T& a, const T& val) { return val < a ? a = val, 1 : 0; }
template<class T> inline int ckmax(T& a, const T& val) { return a < val ? a = val, 1 : 0; }
template<class T> void remDup(vector<T>& v) { sort(ALL(v)); v.erase(unique(ALL(v)), end(v)); }

constexpr int pct(int x) { return __builtin_popcount(x); } // # of bits set
constexpr int bits(int x) { return x == 0 ? 0 : 31-__builtin_clz(x); } // floor(log2(x)) 
constexpr int p2(int x) { return 1<<x; }
constexpr int msk2(int x) { return p2(x)-1; }

ll ceilDiv(ll a, ll b) { return a / b + ((a ^ b) > 0 && a % b); } // divide a by b rounded up
ll floorDiv(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); } // divide a by b rounded down
void setPrec(int x) { cout << fixed << setprecision(x); }

// TO_STRING
#define ts to_string
string ts(char c) { return string(1, c); }
string ts(const char* s) { return (string) s; }
string ts(string s) { return s; }
string ts(bool b) { return (b ? "true" : "false"); }

template<class T> using V = vector<T>;
template<class T> string ts(complex<T> c);
string ts(V<bool> v);
template<size_t sz> string ts(bitset<sz> b);
template<class T> string ts(T v);
template<class T, class U> string ts(pair<T,U> p);
template<class ...U> string ts(tuple<U...> u);

template<class T> string ts(complex<T> c) { stringstream ss; ss << c; return ss.str(); }
string ts(V<bool> v) {string res = "{"; FOR(i,0,SZ(v)-1) res += char('0'+v[i]); res += "}"; return res; }
template<size_t sz> string ts(bitset<sz> b) { string res = ""; FOR(i,0,SZ(b)-1) res += char('0'+b[i]); return res; }
template<class T> string ts(T v) { // containers with begin(), end()
    bool fst = 1; string res = "";
    for (const auto& x: v) { if (!fst) res += " "; fst = 0; res += ts(x); }
    return res;
}
template<class T, class U> string ts(pair<T,U> p) { return "(" + ts(p.FI) + ", " + ts(p.SE) + ")"; }
template<size_t i, class T> string print_tuple_utils(const T& tup) { if constexpr(i == tuple_size<T>::value) return ")"; else return (i ? ", " : "(") + ts(get<i>(tup)) + print_tuple_utils<i + 1, T>(tup); }
template<class ...U> string ts(tuple<U...> u) { return print_tuple_utils<0, tuple<U...>>(u); }

// OUTPUT
template<class T> void pr(T x) { cout << ts(x); }
template<class T, class ...U> void pr(const T& t, const U&... u) { pr(t); pr(u...); }
void ps() { pr("\n"); } // print w/ spaces
template<class T, class ...U> void ps(const T& t, const U&... u) { pr(t); if (sizeof...(u)) pr(" "); ps(u...); }

// DEBUG
void DBG() { cerr << "]" << endl; }
template<class T, class ...U> void DBG(const T& t, const U&... u) { cerr << ts(t); if (sizeof...(u)) cerr << ", "; DBG(u...); }

#ifdef LOCAL_DEBUG
#define CONCAT(x, y) x##y
#define with_level setw(__db_level * 2) << setfill(' ') << "" << setw(0)
#define dbg(...) cerr << with_level << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#define chk(...) if (!(__VA_ARGS__)) cerr << setw(__db_level * 2) << setfill(' ') << "" << setw(0) << "Line(" << __LINE__ << ") -> function(" << __FUNCTION__  << ") -> CHK FAILED: (" << #__VA_ARGS__ << ")" << "\n", exit(0);
#define db_block() debug_block CONCAT(dbbl, __LINE__)
int __db_level = 0;
struct debug_block {
    debug_block() { cerr << with_level << "{" << endl; ++__db_level; }
    ~debug_block() { --__db_level; cerr << with_level << "}" << endl; }
};
#else
#define dbg(...) 0
#define chk(...) 0
#define db_block() 0
#endif

const ld PI = acos(-1.0);
const int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};
const ld EPS = 1e-9;
const ll MODBASE = 1000000007LL;
const int INF = 0x3f3f3f3f;

const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n, m, c[MAXN], num[MAXN], dfsNum, dir[MAXN * MAXN];
vector<vi> a[MAXN];
vpi edges;

void dfs(int u, int p) {
    num[u] = ++dfsNum;
    TRAV(pa, a[u]) {
        int v = pa[0], idx = pa[1], d = pa[2];
        if (v == p) continue;
        if (!num[v]) {
            dir[idx] = d;
            dfs(v, u);
        } else {
            if (num[v] < num[u]) {
                dir[idx] = d;
            }
        }
    }
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n >> m;
    FOR(i,1,m) {
        int u, v;
        cin >> u >> v;
        edges.push_back({u, v});
    }

    FOR(i,1,n) cin >> c[i];

    FOR(i,0,m-1) {
        int u = edges[i].FI, v = edges[i].SE;
        if (c[u] > c[v]) {
            dir[i] = 1;
        } else if (c[u] < c[v]) {
            dir[i] = -1;
        } else {
            a[u].push_back({v, i, 1});
            a[v].push_back({u, i, -1});
        }
    }

    FOR(i,1,n) {
        if (!num[i]) {
            dfs(i, 0);
        }
    }

    FOR(i,0,m-1)
        if (dir[i] == 1) {
            cout << "->\n";
        } else if (dir[i] == -1) {
            cout << "<-\n";
        }
    return 0;
}

Submission Info

Submission Time
Task D - Orientation
User farmerboy
Language C++ (GCC 9.2.1)
Score 600
Code Size 5959 Byte
Status AC
Exec Time 9 ms
Memory 4244 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 3
AC × 52
Set Name Test Cases
Sample example_00, example_01, example_02
All cycle_00, cycle_01, cycle_02, cycle_tree_00, cycle_tree_01, cycle_tree_02, example_00, example_01, example_02, many_small_00, many_small_01, many_small_02, many_small_03, many_small_04, many_small_05, many_small_06, many_small_07, many_small_08, many_small_09, many_small_10, many_small_11, many_small_12, many_small_13, many_small_14, many_small_15, many_small_16, many_small_17, many_small_18, many_small_19, max_random_00, max_random_01, max_random_02, max_random_03, max_random_04, max_random_05, max_random_06, max_random_07, max_random_08, max_random_09, perfect_00, perfect_01, perfect_02, small_00, small_01, small_02, small_03, small_04, small_05, small_06, small_07, small_08, small_09
Case Name Status Exec Time Memory
cycle_00 AC 7 ms 3588 KiB
cycle_01 AC 6 ms 3568 KiB
cycle_02 AC 2 ms 3640 KiB
cycle_tree_00 AC 2 ms 3484 KiB
cycle_tree_01 AC 2 ms 3508 KiB
cycle_tree_02 AC 2 ms 3644 KiB
example_00 AC 2 ms 3624 KiB
example_01 AC 2 ms 3472 KiB
example_02 AC 2 ms 3476 KiB
many_small_00 AC 4 ms 3420 KiB
many_small_01 AC 2 ms 3584 KiB
many_small_02 AC 2 ms 3600 KiB
many_small_03 AC 5 ms 3464 KiB
many_small_04 AC 2 ms 3572 KiB
many_small_05 AC 2 ms 3564 KiB
many_small_06 AC 2 ms 3556 KiB
many_small_07 AC 3 ms 3496 KiB
many_small_08 AC 2 ms 3472 KiB
many_small_09 AC 2 ms 3520 KiB
many_small_10 AC 2 ms 3584 KiB
many_small_11 AC 4 ms 3492 KiB
many_small_12 AC 2 ms 3572 KiB
many_small_13 AC 2 ms 3476 KiB
many_small_14 AC 2 ms 3580 KiB
many_small_15 AC 2 ms 3544 KiB
many_small_16 AC 3 ms 3532 KiB
many_small_17 AC 3 ms 3468 KiB
many_small_18 AC 2 ms 3456 KiB
many_small_19 AC 6 ms 3484 KiB
max_random_00 AC 3 ms 3592 KiB
max_random_01 AC 4 ms 3612 KiB
max_random_02 AC 3 ms 3704 KiB
max_random_03 AC 2 ms 3620 KiB
max_random_04 AC 2 ms 3572 KiB
max_random_05 AC 3 ms 3780 KiB
max_random_06 AC 2 ms 3504 KiB
max_random_07 AC 4 ms 3708 KiB
max_random_08 AC 2 ms 3540 KiB
max_random_09 AC 3 ms 3624 KiB
perfect_00 AC 6 ms 4212 KiB
perfect_01 AC 9 ms 4244 KiB
perfect_02 AC 5 ms 4060 KiB
small_00 AC 2 ms 3572 KiB
small_01 AC 2 ms 3568 KiB
small_02 AC 1 ms 3568 KiB
small_03 AC 2 ms 3396 KiB
small_04 AC 2 ms 3544 KiB
small_05 AC 2 ms 3564 KiB
small_06 AC 2 ms 3444 KiB
small_07 AC 6 ms 3504 KiB
small_08 AC 4 ms 3472 KiB
small_09 AC 1 ms 3432 KiB