Submission #978330

# Submission time Handle Problem Language Result Execution time Memory
978330 2024-05-09T06:24:04 Z vjudge1 Making Friends on Joitter is Fun (JOI20_joitter2) C++17
0 / 100
1 ms 348 KB
#pragma GCC optimize("unroll-loops")
#pragma gcc optimize("Ofast")
#pragma GCC optimization("Ofast")
#pragma optimize(Ofast)
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define str string
#define fs first
#define ss second
#define all(a) a.begin(), a.end()

#define print(a) for(auto x : a) cout << x << ' '; cout << endl;

void __print(signed x) { cerr << x; }
void __print(long long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const str &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const array<int, 2> &x)
{
    cerr << '{';
    __print(x[0]);
    cerr << ',';
    __print(x[1]);
    cerr << '}';
}
template <typename T, typename V>
void __print(const pair<T, V> &x)
{
    cerr << '{';
    __print(x.fs);
    cerr << ',';
    __print(x.ss);
    cerr << '}';
}
template <typename T>
void __print(const T &x)
{
    int f = 0;
    cerr << '{';
    for (auto &y : x)
        cerr << (f++ ? "," : ""), __print(y);
    cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
    __print(t);
    if (sizeof...(v))
        cerr << ", ";
    _print(v...);
}

#define debug(x...)               \
    cerr << "[" << #x << "] = ["; \
    _print(x)
#ifdef ONLINE_JUDGE
#define debug(x...) 42
#endif

const int mod = 1e9 + 7;

void solve(){
    int n, m;
    cin >> n >> m;
    vector<vector<int>> graph(n + 1), rev_graph(n + 1);
    vector<vector<bool>> way(n + 1, vector<bool> (n + 1));
    int last = 0;
    for(int i = 0; i < m; i ++){
        int a, b;
        cin >> a >> b;
        if(way[a][b] == 1){
            cout << last;
            if(i < m - 1)
                cout << endl;
            continue;
        }
        graph[a].push_back(b);
        rev_graph[b].push_back(a);
        way[a][b] = 1;
        int sz = last + 1;
        queue<array<int, 2>> q;
        for(auto x : graph[b]){
            if(x != a and way[x][b] == 1 and way[b][x] == 1){
                way[a][x] = 1;
                sz ++;
                if(way[x][a] == 1)
                    q.push({a, x});
            }
        }
        if(way[a][b] == 1 and way[b][a] == 1)
            q.push({a, b});
        while(!q.empty()){
            array<int, 2> v = q.front();
            q.pop();

            for(auto x : rev_graph[v[0]]){
                if(way[x][v[1]] == 0 and x != v[1]){
                    way[x][v[1]] = 1;
                    sz ++;
                    graph[x].push_back(v[1]);
                    rev_graph[v[1]].push_back(x);
                    if(way[v[1]][x] == 1){
                        q.push({x, v[1]});
                    }
                }
            }
            for(auto x : rev_graph[v[1]]){
                if(way[x][v[0]] == 0 and x != v[0]){
                    way[x][v[0]] = 1;
                    sz ++;
                    graph[x].push_back(v[0]);
                    rev_graph[v[0]].push_back(x);
                    if(way[v[0]][x] == 1)
                        q.push({x, v[0]});
                }
            }
        }
        cout << sz;
        if(i < m - 1)
            cout << endl;
        last = sz;
    }
}

signed main()
{
    fastio;
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
}

Compilation message

joitter2.cpp:2: warning: ignoring '#pragma gcc optimize' [-Wunknown-pragmas]
    2 | #pragma gcc optimize("Ofast")
      | 
joitter2.cpp:3: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
    3 | #pragma GCC optimization("Ofast")
      | 
joitter2.cpp:4: warning: ignoring '#pragma optimize ' [-Wunknown-pragmas]
    4 | #pragma optimize(Ofast)
      |
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Incorrect 1 ms 348 KB Output isn't correct
7 Halted 0 ms 0 KB -