제출 #984370

#제출 시각아이디문제언어결과실행 시간메모리
984370saayan007다리 (APIO19_bridges)C++17
14 / 100
81 ms14164 KiB
#include "bits/stdc++.h" using namespace std; #define int long long #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i) #define repd(i, a, b) for(int (i) = (a); i >= (b); --i) #define em emplace #define eb emplace_back #define pi pair<int, int> #define fr first #define sc second #define mp make_pair const char nl = '\n'; const int mod = 1e9 + 7; const int inf = 1e17; struct UFDS { int n; vector<int> lnk, sz; void init(int N) { n = N; lnk.resize(n); sz.resize(n); rep(i, 0, n - 1) { lnk[i] = i; sz[i] = 1; } } int find(int x) { return (x == lnk[x] ? x : lnk[x] = find(lnk[x])); } void unite(int x, int y) { x = find(x); y = find(y); if(x == y) return; if(sz[x] < sz[y]) swap(x, y); lnk[y] = x; sz[x] += sz[y]; } int qry(int x) { return sz[find(x)]; } }; #warning constants according to subtask const int N = 5e4L + 10; const int M = 1e5L + 10; int n, m, q; int ed[M][3]; UFDS uf; using dt = array<int, 4>; dt A[2*M]; int ans[M]; int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; rep(i, 1, m) { rep(j, 0, 2) cin >> ed[i][j]; A[i][0] = ed[i][2]; A[i][1] = ed[i][0]; A[i][2] = ed[i][1]; A[i][3] = -1; } cin >> q; rep(i, 1, q) { int t; cin >> t; if(t == 1) { int b, r; cin >> b >> r; /* modify(b, r); */ } else { int s, w; cin >> s >> w; A[m + i][0] = w; A[m + i][1] = s; A[m + i][2] = 0; A[m + i][3] = i; /* query(s, w); */ } } sort(A + 1, A + m + q + 1, [&](dt &left, dt &right) { return mp(left[0], -left[3]) > mp(right[0], -right[3]); }); uf.init(n + 1); rep(i, 1, m + q) { if(A[i][3] < 0) { uf.unite(A[i][2], A[i][1]); } else { ans[A[i][3]] = uf.qry(A[i][1]); } } rep(i, 1, q) { cout << ans[i] << nl; } }

컴파일 시 표준 에러 (stderr) 메시지

bridges.cpp:50:2: warning: #warning constants according to subtask [-Wcpp]
   50 | #warning constants according to subtask
      |  ^~~~~~~
bridges.cpp: In member function 'void UFDS::init(long long int)':
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:27:9: note: in expansion of macro 'rep'
   27 |         rep(i, 0, n - 1) {
      |         ^~~
bridges.cpp: In function 'int32_t main()':
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:65:5: note: in expansion of macro 'rep'
   65 |     rep(i, 1, m) {
      |     ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:66:9: note: in expansion of macro 'rep'
   66 |         rep(j, 0, 2) cin >> ed[i][j];
      |         ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:75:5: note: in expansion of macro 'rep'
   75 |     rep(i, 1, q) {
      |     ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:95:5: note: in expansion of macro 'rep'
   95 |     rep(i, 1, m + q) {
      |     ^~~
bridges.cpp:5:30: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    5 | #define rep(i, a, b) for(int (i) = (a); i <= (b); ++i)
      |                              ^
bridges.cpp:103:5: note: in expansion of macro 'rep'
  103 |     rep(i, 1, q) {
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...