답안 #430804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430804 2021-06-17T05:28:53 Z 2qbingxuan 조이터에서 친구를 만드는건 재밌어 (JOI20_joitter2) C++14
0 / 100
3 ms 4940 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#ifdef local
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define pary(a...) danb(#a, a)
#define debug(a...) qqbx(#a, a)
template <typename ...T> void qqbx(const char *s, T ...a) {
    int cnt = sizeof...(T);
    ((std::cerr << "\033[1;32m(" << s << ") = (") , ... , (std::cerr << a << (--cnt ? ", " : ")\033[0m\n")));
}
template <typename T> void danb(const char *s, T L, T R) {
    std::cerr << "\033[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        std::cerr << (f++ ? ", " : "") << *L;
    std::cerr << " ]\033[0m\n";
}
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#define pary(...) ((void)0)
#endif // local
#define all(v) begin(v),end(v)
#define pb emplace_back

using namespace std;
using ll = long long;
using ld = long double;
template <typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
const int mod = 1000000007;
const int inf = 1e9;
const ll INF = 1e18;
const int maxn = 100025;

bool qlig[maxn];
bool nearQlig[maxn];
vector<int> out[maxn], in[maxn];
signed main() {
    ios_base::sync_with_stdio(0), cin.tie(0);
    int n, m;
    cin >> n >> m;
    set<pair<int,int>> st;
    queue<int> q;
    ll qcnt = 0;
    while (m--) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        out[a].pb(b);
        in[b].pb(a);
        if (st.count({ b, a }) || (qlig[a] && !qlig[b] && nearQlig[b])) {
            if (!qlig[a]) {
                qlig[a] = true;
                qcnt += 1;
                q.push(a);
                for (int j: in[a])
                    nearQlig[j] = true;
            }
            if (!qlig[b]) {
                qlig[b] = true;
                qcnt += 1;
                q.push(b);
                for (int j: in[b])
                    nearQlig[j] = true;
            }
        }
        st.insert({ a, b });
        while (!q.empty()) {
            int i = q.front(); q.pop();
            for (int j: out[i]) {
                if (!qlig[j] && nearQlig[j]) {
                    qlig[j] = true;
                    qcnt += 1;
                    q.push(j);
                    for (int k: in[j])
                        nearQlig[k] = true;
                }
            }
        }
        int nqcnt = 0;
        for (int i = 0; i < n; i++) if (!qlig[i] && nearQlig[i]) nqcnt += 1;
        ll ans = qcnt * (qcnt - 1) + nqcnt * qcnt;
        for (auto [s, t]: st) {
            if (!qlig[t]) {
                ++ans;
            }
        }
        cout << ans << '\n';
    }
}

Compilation message

joitter2.cpp: In function 'int main()':
joitter2.cpp:82:19: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   82 |         for (auto [s, t]: st) {
      |                   ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 4940 KB Output isn't correct
2 Halted 0 ms 0 KB -