제출 #123406

#제출 시각아이디문제언어결과실행 시간메모리
123406figter001다리 (APIO19_bridges)C++17
14 / 100
125 ms7880 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef unsigned long long ull; const int nax = 1e5 + 100; int dsu[nax],sz[nax],ans[nax]; int n,m,q; int find(int u){ return u == dsu[u] ? u : dsu[u] = find(dsu[u]); } int main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){ dsu[i] = i; sz[i] = 1; } vector<pair<int,pair<int,int>>> e; for(int i=0;i<m;i++){ int u,v,w; scanf("%d%d%d",&u,&v,&w); e.push_back({w,{u,v}}); // e.emplace_back(w,u,v); } scanf("%d",&q); for(int i=1;i<=q;i++){ int t,s,w; scanf("%d%d%d",&t,&s,&w); e.push_back({w,{-s,-i}}); // e.emplace_back(w,s,-1); } sort(e.begin(),e.end()); reverse(e.begin(),e.end()); for(int i=0;i<e.size();i++){ if(e[i].second.second < 0){ int id = -e[i].second.first; int at = -e[i].second.second; ans[at] = sz[find(id)]; }else{ int u = e[i].second.first; int v = e[i].second.second; u = find(u); v = find(v); if(u != v){ sz[u] += sz[v]; dsu[v] = u; } } } for(int i=1;i<=q;i++){ printf("%d\n", ans[i]); } }

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

bridges.cpp: In function 'int main()':
bridges.cpp:40:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<e.size();i++){
              ~^~~~~~~~~
bridges.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d",&n,&m);
  ~~~~~^~~~~~~~~~~~~~
bridges.cpp:27:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&u,&v,&w);
   ~~~~~^~~~~~~~~~~~~~~~~~~
bridges.cpp:31:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
bridges.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d",&t,&s,&w);
   ~~~~~^~~~~~~~~~~~~~~~~~~
#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...