Submission #2211062


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<vector<int>> vst;
    vst.resize(n);
    for(vector<int> &row : vst){
        row.resize(12);
        for(int &cell : row){
            cell=0;
        }
    }
    for(size_t i=operations.size()-1; ~i; i--){
        const Operation &operation=operations[i];
        queue<Vertice*> que;
        que.push((Vertice*)(&vertices[operation.getV()]));
        dst[operation.getV()]=operation.getD();
        for(; !que.empty(); que.pop()){
            Vertice *u=que.front();
            if(vst[u->getIndex()][dst[u->getIndex()]])continue;
            vst[u->getIndex()][dst[u->getIndex()]]=1;
            if(!~foo[u->getIndex()])
                foo[u->getIndex()]=operation.getC();
            if(dst[u->getIndex()]>0){
                for(Vertice *v : u->getNeighbors()){
                    que.push(v);
                    dst[v->getIndex()]=dst[u->getIndex()]-1;
                }
            }
        }
    }
    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 2915 Byte
Status RE
Exec Time 107 ms
Memory 12800 KB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:92: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:98:24: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &q);
                        ^
./Main.cpp:102: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
RE × 2
RE × 12
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 99 ms 384 KB
00_example_02.txt RE 97 ms 256 KB
01.txt RE 99 ms 256 KB
02.txt RE 100 ms 256 KB
03.txt RE 98 ms 256 KB
04.txt RE 97 ms 256 KB
05.txt RE 97 ms 384 KB
06.txt RE 98 ms 3328 KB
07.txt RE 107 ms 12800 KB
08.txt RE 99 ms 3328 KB
09.txt RE 98 ms 3328 KB
10.txt RE 98 ms 3328 KB