제출 #62014

#제출 시각아이디문제언어결과실행 시간메모리
62014hamzqq9Min-max tree (BOI18_minmaxtree)C++14
7 / 100
217 ms45536 KiB
#include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define ppb pop_back #define umax(x,y) x=max(x,y) #define umin(x,y) x=min(x,y) #define ll long long #define ii pair<int,int> #define iii pair<ii,int> #define sz(x) (x.size()) #define orta ((bas+son)>>1) #define all(x) x.begin(),x.end() #define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" " #define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar() #define pw(x) (1<<(x)) #define inf 1000000005 #define MOD 1000000007 #define N 240015 #define LOG 20 using namespace std; struct query { int from,to,cost; bool operator<(const query& oth) const { return cost<oth.cost; } }; vector<query> Max,Min; int n,q,x,y,z,totnode; int dis[N],match[N],deep[N],ata[N],der[N],par[N]; vector<int> v[N],v2[N]; int bul(int node) { if(ata[node]==node) return node; return ata[node]=bul(ata[node]); } void dfs(int node) { if(node) { for(int i:v2[node]) { if(dis[node]+1==dis[match[i]]) { dfs(match[i]); if(dis[match[i]]!=inf) { match[node]=i; match[i]=node; return ; } } } dis[node]=inf; } } bool bfs() { queue<int> q; for(int i=1;i<=n;i++) { if(!match[i]) { dis[i]=0; q.push(i); } else dis[i]=inf; } dis[0]=inf; while(!q.empty()) { int node=q.front(); q.pop(); if(dis[node]<dis[0]) { for(int i:v2[node]) { if(dis[match[i]]==inf) { dis[match[i]]=dis[node]+1; q.push(match[i]); } } } } return (dis[0]!=inf); } void hopcroft_karp() { while(bfs()) { for(int i=1;i<=n;i++) if(!match[i]) dfs(i); } } void make(int node,int from,int to) { while(1) { from=bul(from); to=bul(to); if(to==from) return ; if(der[from]<der[to]) swap(from,to); v2[node].pb(from); v2[from].pb(node); ata[from]=par[from]; } } void init() { for(int i=1;i<=n;i++) { ata[i]=i; } } void dfs(int node,int ata) { par[node]=ata; der[node]=der[ata]+1; for(int i:v[node]) { if(i==ata) continue ; dfs(i,node); } } int main() { // freopen("input.txt","r",stdin); scanf("%d",&n); for(int i=1;i<n;i++) { scanf("%d %d",&x,&y); v[x].pb(y); v[y].pb(x); } dfs(1,0); scanf("%d",&q); while(q--) { char c; scanf(" %c %d %d %d",&c,&x,&y,&z); if(c=='m') Min.pb({x,y,z}); else Max.pb({x,y,z}); } sort(all(Min)); reverse(all(Min)); sort(all(Max)); init(); for(int i=0;i<sz(Max);i++) make(i+1+n,Max[i].from,Max[i].to); init(); for(int i=0;i<sz(Min);i++) make(i+1+sz(Max)+n,Min[i].from,Min[i].to); hopcroft_karp(); for(int i=2;i<=n;i++) { int cst; if(match[i]<=n+sz(Max)) cst=Max[match[i]-n-1].cost; else cst=Min[match[i]-n-sz(Max)-1].cost; printf("%d %d %d\n",i,par[i],cst); } }

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

minmaxtree.cpp: In function 'int main()':
minmaxtree.cpp:214:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<sz(Max);i++) make(i+1+n,Max[i].from,Max[i].to);
               ^
minmaxtree.cpp:218:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=0;i<sz(Min);i++) make(i+1+sz(Max)+n,Min[i].from,Min[i].to);
               ^
minmaxtree.cpp:226:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(match[i]<=n+sz(Max)) cst=Max[match[i]-n-1].cost;
              ^
minmaxtree.cpp:182:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
minmaxtree.cpp:186:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&x,&y);
   ~~~~~^~~~~~~~~~~~~~~
minmaxtree.cpp:195:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&q);
  ~~~~~^~~~~~~~~
minmaxtree.cpp:201:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c %d %d %d",&c,&x,&y,&z);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...