제출 #95459

#제출 시각아이디문제언어결과실행 시간메모리
95459mzhaoPraktični (COCI18_prakticni)C++11
26 / 130
445 ms31740 KiB
#include <bits/stdc++.h> using namespace std; #ifdef DEBUG #define D(x...) printf(x) #else #define D(x...) #endif #define x first #define y second #define MN 100100 int N, M; struct End { int n, w, i; }; vector<End> adj[MN]; int dep[MN]; bool vis[MN]; vector<int> st; bool visEdge[MN]; int valEdge[MN]; set<int> vals; bool bitAdj[32][32], bitNo[32][32], bitVis[32], bv[32]; int comp[32], compVal[32], nc; set<int> applyto[32]; void dfs(int n, int d) { vis[n] = 1; dep[n] = d; for (End i : adj[n]) if (!vis[i.n]) { st.push_back(st.back() ^ i.w); dfs(i.n, d+1); st.pop_back(); } else if (dep[i.n] < d) { int val = st.back() ^ st[dep[i.n]] ^ i.w; if (val) { visEdge[i.i] = 1; valEdge[i.i] = val; vals.insert(val); } } } void dfs2(int k, int c) { bv[k] = 1; comp[k] = c; compVal[c] |= 1<<k; for (int i = 0; i < 30; i++) if (bitAdj[i][k] && !bitNo[i][k] && !bv[i]) dfs2(i, c); } int main() { scanf("%d%d", &N, &M); for (int i = 1, A, B, C; i <= M; i++) { scanf("%d%d%d", &A, &B, &C); adj[A].push_back({B, C, i}); adj[B].push_back({A, C, i}); } st.push_back(0); dfs(1, 0); D("vals = "); for (int i : vals) D("%d ", i); D("\n"); for (int i : vals) { for (int j = 0; j < 30; j++) if ((1<<j) & i) { bitVis[j] = 1; for (int k = 0; k < 30; k++) if (j != k) { if ((1<<k) & i) bitAdj[j][k] = bitAdj[k][j] = 1; else bitNo[j][k] = bitNo[k][j] = 1; } } } for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) D("%d ", bitAdj[i][j] && !bitNo[i][j]); D("\n"); } for (int i = 0; i < 30; i++) if (bitVis[i] && !bv[i]) dfs2(i, nc++); for (int i = 0; i < nc; i++) D("comp = %d val = %d\n", i, compVal[i]); for (int i = 1; i <= M; i++) if (visEdge[i]) for (int j = 0; j < 30; j++) if ((1<<j) & valEdge[i]) applyto[comp[j]].insert(i); D("ANS:\n\n"); printf("%d\n", nc); for (int i = 0; i < nc; i++) { printf("%d %d", compVal[i], applyto[i].size()); for (int j : applyto[i]) printf(" %d", j); printf("\n"); } }

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

parkticni.cpp: In function 'int main()':
parkticni.cpp:69:11: warning: unused variable 'i' [-Wunused-variable]
  for (int i : vals) D("%d ", i);
           ^
parkticni.cpp:92:48: warning: format '%d' expects argument of type 'int', but argument 3 has type 'std::set<int>::size_type {aka long unsigned int}' [-Wformat=]
   printf("%d %d", compVal[i], applyto[i].size());
                               ~~~~~~~~~~~~~~~~~^
parkticni.cpp:60:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &N, &M);
  ~~~~~^~~~~~~~~~~~~~~~
parkticni.cpp:62:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &A, &B, &C);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...