Submission #1261593

#TimeUsernameProblemLanguageResultExecution timeMemory
1261593Bui_Quoc_CuongCollapse (JOI18_collapse)C++20
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "collapse.h" using namespace std; #define FOR(i, a, b) for(int i = a; i <= (int)b; i++) #define FORD(i, a, b) for(int i = a; i >= (int)b; i--) #define all(a) a.begin(), a.end() #define pb push_back #define fi first #define se second const int maxN = 3e5 + 5; int n, m, q; array <int, 3> edges[maxN]; array <int, 2> Q[maxN]; // void init() { // cin >> n >> m >> q; // FOR(i, 1, m) { // cin >> edges[i][0] >> edges[i][1] >> edges[i][2]; // if (edges[i][1] > edges[i][2]) swap(edges[i][1], edges[i][2]); // } // FOR(i, 1, q) { // cin >> Q[i][0] >> Q[i][1]; // } // } namespace sub1 { bool checksub() { return max(n, q) <= 5000; } int lab[maxN]; int ssc; int find (int x) { return lab[x] < 0 ? x : lab[x] = find(lab[x]); } bool joint (int u, int v) { int x = find(u), y = find(v); if (x == y) return 0; if (lab[x] > lab[y]) swap(x, y); lab[x]+= lab[y]; lab[y] = x; ssc--; return 1; } vector <int> solve() { vector <int> res; FOR(_q, 1, q) { FOR(i, 1, n) lab[i] = - 1; ssc = n; set <pair <int, int>> edge_query; FOR(i, 1, Q[_q][0] + 1) { if (edges[i][0] == 0) { if (edge_query.find(make_pair(edges[i][1], edges[i][2])) != edge_query.end()) { edge_query.erase(edge_query.find(make_pair(edges[i][1], edges[i][2]))); } } else { if (edges[i][1] <= Q[_q][1] && edges[i][2] >= Q[_q][1] + 1) { continue; } edge_query.insert(make_pair(edges[i][1], edges[i][2])); } } for (auto &it : edge_query) joint(it.first, it.second); res.push_back(ssc); } return res; } } vector <int> simulateCollapse(int N, vector<int> T, vector<int> X, vector<int> Y, vector<int> W, vector<int> P) { n = N; m = X.size(); q = W.size(); FOR(i, 0, m - 1) { edges[i + 1][0] = T[i]; edges[i + 1][1] = X[i]; edges[i + 1][2] = Y[i]; if (edges[i + 1][1] > edges[i + 1][2]) swap(edges[i + 1][1], edges[i + 1][2]); } for (int i = 0; i < q; i++) { Q[i + 1][0] = W[i]; Q[i + 1][1] = P[i]; } vector <int> res = sub1::solve(); return res; } void process() { if(sub1::checksub()) sub1::solve(); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define ko "kieuoanh" if (fopen(ko".inp", "r")) { freopen(ko".inp", "r", stdin); freopen(ko".out", "w", stdout); } vector <int> res = simulateCollapse(4, {1, 1, 1, 1}, {1, 2, 3, 2}, {2, 3, 4, 4}, {2, 0}, {3, 3}); for (int &v : res) cout << v << " "; return 0; }

Compilation message (stderr)

collapse.cpp: In function 'int main()':
collapse.cpp:101:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |         freopen(ko".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
collapse.cpp:102:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |         freopen(ko".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccOmdXr3.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccxI5Xyd.o:collapse.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status