Submission #2212826
Source Code Expand
#include "bits/stdc++.h"
using namespace std;
class Vertice{
private:
int idx;
vector<Vertice*> neighbors;
public:
void clear(){
this->neighbors.clear();
}
void addNeighbor(Vertice* neighbor){
this->neighbors.push_back(neighbor);
}
vector<Vertice*> &getNeighbors(){
return this->neighbors;
}
void setIndex(const int index){
this->idx=index;
}
int getIndex(){
return this->idx;
}
};
class Operation{
private:
int v, d, c;
public:
Operation(const int lhs, const int mhs, const int rhs){
this->v=lhs;
this->d=mhs;
this->c=rhs;
}
int getV() const{
return this->v;
}
int getD() const{
return this->d;
}
int getC() const{
return this->c;
}
};
vector<int> painting(const int n, const vector<Operation> &operations, const vector<Vertice> &vertices){
vector<int> foo(n, -1);
vector<int> dst(n, 0);
vector<int> vst(n, -1);
for(int i=operations.size()-1; i>=0; i--){
const Operation &operation=operations[i];
queue<Vertice*> que;
dst[operation.getV()]=operation.getD();
if(dst[operation.getV()]>vst[operation.getV()]){
vst[operation.getV()]=dst[operation.getV()];
que.push((Vertice*)(&vertices[operation.getV()]));
}
for(; !que.empty(); que.pop()){
Vertice *u=que.front();
if(!~foo[u->getIndex()])
foo[u->getIndex()]=operation.getC();
if(dst[u->getIndex()]>0){
for(Vertice *v : u->getNeighbors()){
if(dst[u->getIndex()]-1>vst[v->getIndex()]){
dst[v->getIndex()]=dst[u->getIndex()]-1;
que.push(v);
vst[v->getIndex()]=dst[v->getIndex()];
}
}
}
}
}
for(int &x : foo){
x=max(x, 0);
}
return foo;
}
int main(){
int n, m, q;
while(scanf("%d%d", &n, &m)!=EOF){
vector<Vertice> vertices;
vertices.resize(n);
for(int i=0; i<n; i++){
vertices[i].setIndex(i);
}
for(int i=0; i<m; i++){
int u, v;
scanf("%d%d", &u, &v);
u--;
v--;
vertices[u].addNeighbor(&vertices[v]);
vertices[v].addNeighbor(&vertices[u]);
}
scanf("%d", &q);
vector<Operation> operations;
for(int i=0; i<q; i++){
int v, d, c;
scanf("%d%d%d", &v, &d, &c);
operations.push_back(Operation(v-1, d, c));
}
vector<int> foo=painting(n, operations, vertices);
for(const int r : foo){
printf("%d\n", r);
}
}
return 0;
}
Submission Info
Submission Time |
|
Task |
A - AtCoder Group Contest |
User |
jki14 |
Language |
C++14 (GCC 5.4.1) |
Score |
0 |
Code Size |
2936 Byte |
Status |
RE |
Exec Time |
149 ms |
Memory |
4480 KB |
Compile Error
./Main.cpp: In function ‘int main()’:
./Main.cpp:89:34: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &u, &v);
^
./Main.cpp:95:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &q);
^
./Main.cpp:99:40: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &v, &d, &c);
^
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
0 / 300 |
Status |
|
|
Set Name |
Test Cases |
Sample |
00_example_01.txt, 00_example_02.txt |
All |
00_example_01.txt, 00_example_02.txt, 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt |
Case Name |
Status |
Exec Time |
Memory |
00_example_01.txt |
RE |
112 ms |
640 KB |
00_example_02.txt |
RE |
98 ms |
256 KB |
01.txt |
RE |
98 ms |
256 KB |
02.txt |
RE |
96 ms |
256 KB |
03.txt |
RE |
98 ms |
256 KB |
04.txt |
RE |
98 ms |
256 KB |
05.txt |
RE |
98 ms |
384 KB |
06.txt |
RE |
99 ms |
3328 KB |
07.txt |
RE |
149 ms |
4480 KB |
08.txt |
RE |
99 ms |
3328 KB |
09.txt |
RE |
99 ms |
3328 KB |
10.txt |
RE |
100 ms |
3328 KB |