#include<iostream>
#include<map>
#include<vector>
#include<algorithm>
#define pb push_back
using namespace std;
struct edge{
int x;
int y;
int z;
bool operator<(const edge &rhs)const{return rhs.z<z;};
}q[70005];
struct par{
int x;
int y;
bool operator<(const par &rhs)const{return rhs.x>x;};
};
map<par,int> mym;
vector<int> adj[70005];
bool dfs(int s,int d,int v,bool vis[]){
vis[s]=true;
if(s==d){
return true;
}
bool c=false;
for(int i=0; i<adj[s].size(); i++){
if(!vis[adj[s].at(i)]){
if(dfs(adj[s].at(i),d,v,vis)){
par t; t.x=min(s,adj[s].at(i)); t.y=max(s,adj[s].at(i));
mym[t]=v;
c=true;
break;
}
}
}
return c;
}
int main(){
int N;
cin>>N;
for(int i=0; i<N-1; i++){
int t1,t2;
cin>>t1>>t2;
adj[t1].pb(t2);
adj[t2].pb(t1);
par t; t.x=min(t1,t2); t.y=max(t1,t2);
mym[t]=-1;
}
int K;
cin>>K;
for(int i=0; i<K; i++){
char e;
cin>>e>>q[i].x>>q[i].y>>q[i].z;
}
sort(q,q+K);
for(int i=0; i<K; i++){
bool vis[700005]={false};
dfs(q[i].x,q[i].y,q[i].z,vis);
}
for(map<par,int>::iterator it=mym.begin(); it!=mym.end(); it++){
cout<<(it->first).x<<" "<<(it->first).y<<" "<<it->second<<endl;
}
return 0;
}
Compilation message
minmaxtree.cpp: In function 'bool dfs(int, int, int, bool*)':
minmaxtree.cpp:26:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0; i<adj[s].size(); i++){
~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2680 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1056 ms |
15988 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
9080 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
5 ms |
2680 KB |
Unexpected end of file - int32 expected |
2 |
Halted |
0 ms |
0 KB |
- |